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){
lPcToUpdate.add(lpc);
}
else if(lpc.Primary_Email__c != oldPc.Primary_Email__c){
lPcToUpdate.add(lpc);
}
}
return lPcToUpdate;