You need to sign in to do that
Don't have an account?
roni shore
check null value in oldMap
Hi Guys,
getting variable does not exist when checking the old value is null or not. please suggest
public static Boolean HasAccess(List<AccountContactRelation> lstNew) {
for (AccountContactRelation acr : lstNew) {
system.debug('trigOld-->'+trigger.oldMap.get(acr.Id));
if(string.isNotBlank(acr.Entity__c) || string.isNotBlank(trigger.oldMap.get(acr.Id).External_Entity__c) ){// getting error on this line checking oldmap
if(acr.External_Entity__c != 'Customer-facing')
throw new acrException(System.Label.Cimited);
}
}
return bReturn;
}
getting variable does not exist when checking the old value is null or not. please suggest
public static Boolean HasAccess(List<AccountContactRelation> lstNew) {
for (AccountContactRelation acr : lstNew) {
system.debug('trigOld-->'+trigger.oldMap.get(acr.Id));
if(string.isNotBlank(acr.Entity__c) || string.isNotBlank(trigger.oldMap.get(acr.Id).External_Entity__c) ){// getting error on this line checking oldmap
if(acr.External_Entity__c != 'Customer-facing')
throw new acrException(System.Label.Cimited);
}
}
return bReturn;
}
Modify your if statement to check if the Trigger.OldMap has the Id value.
if(string.isNotBlank(acr.Entity__c) || (Trigger.OldMap.keySet().contains(acr.Id) && string.isNotBlank(trigger.oldMap.get(acr.Id).External_Entity__c) ) )
Regards,
mirki
public static Boolean HasAccess(List<AccountContactRelation> lstNew) {
for (AccountContactRelation acr : lstNew) {
system.debug('trigOld-->'+trigger.oldMap.get(acr.Id));
if(acr.Entity__c!=NULL || Trigger.oldMap.get(acr.Id).External_Entity__c!=NULL ){// getting error on this line checking oldmap
if(acr.External_Entity__c != 'Customer-facing')
throw new acrException(System.Label.Cimited);
}
}
return bReturn;
}
Also try to use "trigger.oldMap.get(acr.Id) != null" in if condition.