You need to sign in to do that
Don't have an account?
Miranda L 2
Null Pointer exceptoin error
I need help to improve my code because in this method I am getting Nullpointerexception please suggest me
private void storeData(){ Map<ID,Invoice__c> newInvoices = (Map<ID,Invoice__c>) Trigger.newMap; for(Invoice__c i: newInvoices.Values()){ newEntitiesIds.add(i.Account__c); } if(Trigger.isUpdate){ for(Invoice__c i: (List<Invoice__c>) Trigger.Old){ if(i.Account__c != newInvoices.get(i.id).Account__c){ oldEntitiesIds.add(i.Account__c); } } } }
Please let us know the line No where you are getting the Null Exception:
just try the below change:
private void storeData(){
Map<ID,Invoice__c> newInvoices = (Map<ID,Invoice__c>) Trigger.newMap;
for(Invoice__c i: newInvoices.Values()){
newEntitiesIds.add(i.Account__c);
}
if(Trigger.isUpdate){
for(Invoice__c i: (List<Invoice__c>) Trigger.Old){
if(newInvoices.containsKey(i.id))
{
if(i.Account__c != newInvoices.get(i.id).Account__c){
oldEntitiesIds.add(i.Account__c);
}
}
}
}
}
Thanks,
Maharajan.C
I am getting this error on line numbers
System.NullPointerException: Attempt to de-reference a null object\n\nClass.TriggerGroup.storeData: line 27, column 1\nClass.TriggerGroup.Handle: line 18, column 1\nExternal entry
here is my code
Try the following updated code:
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
I am not able to save my code, I am getting following error
Got it, please try the following:
Thanks,
Ajay Dubedi