You need to sign in to do that
Don't have an account?
Dman100
The trigger works if the MDR_Account__c field in the lead object is already populated and I run the update. However, if I edit the lead and do the lookup on the MDR_Account__c field, the NullPointerException error is thrown.
NullPointerException: Attempt to de-reference a null object:
I am getting a NullPointerException: Attempt to de-reference a null object error on the following trigger code:
Code:
trigger ImportMDRDataTrigger on Lead (before update) { Lead[] leadList = [Select Id, MDR_Account__r.Enrollment__c, MDR_Account__r.MDR_School_I_D__c, MDR_Account__r.MDR_District_I_D__c from Lead WHERE MDR_Account__c != null and Id in :Trigger.new]; Map<Id, Lead> leadMap = new Map<Id, Lead>(leadList); for (Lead l : Trigger.new) { if (l.MDR_Account__c == null) continue; Lead the_lead = leadMap.get(l.Id); l.Enrollment__c = the_lead.MDR_Account__r.Enrollment__c; l.MDR_District_PID__c = the_lead.MDR_Account__r.MDR_District_I_D__c; l.MDR_School_PID__c = the_lead.MDR_Account__r.MDR_School_I_D__c; } }
The trigger works if the MDR_Account__c field in the lead object is already populated and I run the update. However, if I edit the lead and do the lookup on the MDR_Account__c field, the NullPointerException error is thrown.
Thanks for any help.
Message Edited by arnt72 on 10-13-2008 04:52 PM
Message Edited by arnt72 on 10-13-2008 04:55 PM
Message Edited by arnt72 on 10-13-2008 04:57 PM
All Answers
If your intention is to fill in the values from the parent for every Lead you could get the values to Lead detail page also by creating a formula field.
Thanks.
But your SOQL query won't work as expected in this case. Instead you should look at querying MDR_Account__c directly, like:
Message Edited by arnt72 on 10-13-2008 04:52 PM
Message Edited by arnt72 on 10-13-2008 04:55 PM
Message Edited by arnt72 on 10-13-2008 04:57 PM