I'm fairly new to coding within Salesforce, and am running into an issue. I'm hoping that it is something small that I'm overlooking here, but I can't figure out why I'm getting this error. The code overall is designed to look for a Primary email and phone number on child records and update the parent (this is the code I'm working with to learn and isn't something we are going to actually be using, I just need to make it work so I can utilize this method later).

Here is the block of code I'm working in, the error occurs at "SObject o = oldMapIn.get(lpc.id);"

private List<Personal_Contact__c> addChangedToList (List<Personal_Contact__c> lpc, Map<id, SObject> oldMapIn){

        List<Personal_Contact__c> lPcToUpdate= new List<Personal_Contact__c>();
        if(lpc==null){return null;}
        if(oldMapIn==null){return null;}

        for (Personal_Contact__c pc : lpc){

            SObject o = oldMapIn.get(lpc.id);

            if(o !=null){
                Personal_Contact__c oldPc=(Personal_Contact__c) o;
                if (lpc.Primary_Phone__c != oldPc.Primary_Phone__c){
                else if(lpc.Primary_Email__c != oldPc.Primary_Email__c){
        return lPcToUpdate;

1 Answer 1


The problem is that you're attempting to use the list (lpc) to get the Id from the map instead of the single record (pc) in the for loop. It should read:

SObject o = oldMapIn.get(pc.id);

In fact, everywhere you use lpc inside of that for loop should be changed to pc.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .