You need to sign in to do that
Don't have an account?

execution of BeforeUpdate caused by: System.NullPointerException: Attempt to de-reference a null object:
Hi,
I saved the trigger sucessully, however, when I am saving the BLC_Lead__c record from UI, then I am getting the error in the bold font written line and the error is Salesforce - Unlimited EditionSystem.NullPointerException: Attempt to de-reference a null object: Trigger.EnableCurfewedOnLeads: line 23, column 1 :
trigger EnableCurfewedOnLeads on BLC_Lead__c (before update) {
//Iterate over all the Leads to retrieve the Curfew ID
Set<Id> setCurfewIds = new Set<Id>();
for(BLC_Lead__c blcLead : Trigger.new){
setCurfewIds.add(blcLead.Call_Curfew_Details__r.id);
}
// Retrieve all Curfews and create a map of Curfews
Map<Id,Call_Curfew_Details__c> mapCurfews = new Map<Id,Call_Curfew_Details__c>([SELECT Id, IsCurfew__c FROM Call_Curfew_Details__c where Id IN:setCurfewIds]);
//Iterate all over the Leads and Populate the flag isCurfew = TRUE
for(BLC_Lead__c leds: Trigger.new){
if(leds != null && leds != null){
Call_Curfew_Details__c relatedCurfews = mapCurfews.get(leds.Call_Curfew_Details__r.id); leds.IsCurfew__c = relatedCurfews.IsCurfew__c;
}
}
}
I saved the trigger sucessully, however, when I am saving the BLC_Lead__c record from UI, then I am getting the error in the bold font written line and the error is Salesforce - Unlimited EditionSystem.NullPointerException: Attempt to de-reference a null object: Trigger.EnableCurfewedOnLeads: line 23, column 1 :
trigger EnableCurfewedOnLeads on BLC_Lead__c (before update) {
//Iterate over all the Leads to retrieve the Curfew ID
Set<Id> setCurfewIds = new Set<Id>();
for(BLC_Lead__c blcLead : Trigger.new){
setCurfewIds.add(blcLead.Call_Curfew_Details__r.id);
}
// Retrieve all Curfews and create a map of Curfews
Map<Id,Call_Curfew_Details__c> mapCurfews = new Map<Id,Call_Curfew_Details__c>([SELECT Id, IsCurfew__c FROM Call_Curfew_Details__c where Id IN:setCurfewIds]);
//Iterate all over the Leads and Populate the flag isCurfew = TRUE
for(BLC_Lead__c leds: Trigger.new){
if(leds != null && leds != null){
Call_Curfew_Details__c relatedCurfews = mapCurfews.get(leds.Call_Curfew_Details__r.id); leds.IsCurfew__c = relatedCurfews.IsCurfew__c;
}
}
}
Try the code as below:
Hi,
Its better to use containskey before geeting data from map.
try this code
Thanks.