When we use dataloader to upload records into database we have got the null pointer error when we use the related salesforce Id. But it works when we switch to use external Id.
I am just puzzled to find out the reason.
Below is my related trigger code:
List<String> relatedOlIdList = new List<String>();
for(UK_Job__c job : (List<UK_Job__c>)Trigger.New)
{
relatedOlIdList.add(job.UK_Order_Line__c);
}
relatedOlMap = new Map<Id, UK_Order_Line__c>([Select Id, Name,
Turnaround__c,
Transcript_Due__c
From UK_Order_Line__c
Where Id in :relatedOlIdList]);
//...
UK_Order_Line__c relatedOl = relatedOlMap.get(job.UK_Order_Line__c);
if(relatedOl.Transcript_Due__c == null) // This is the line getting null pointer reference error
I have double checked that in the .csv file, the related UK_Order_Line__c Id is valid and does exist in the system. And if we switch into external Id it just works.
But it is really weird that it can't find the relatedOl in this case.
Both code are executed both in before insert and before update.
if(relatedOl != null && relatedOl.Transcript_Due__c == null)
... or use aMap.containsKey()
call – Caspar Harmer Jun 5 '18 at 7:50