You need to sign in to do that
Don't have an account?
Hermann Ouré
How to Fix Trigger Error: System.NullPointerException: Attempt to de-reference a null object
Hello,
I have created a trigger on Order object to update an account's custom field (Chiffre_d_affaire__c) when an order has been made.
But when trying to add a product to the order. I have an error:
How could I fix that error?
thank you
here is my trigger:
I have created a trigger on Order object to update an account's custom field (Chiffre_d_affaire__c) when an order has been made.
But when trying to add a product to the order. I have an error:
How could I fix that error?
thank you
here is my trigger:
trigger UpdateAccountCA on Order (after update) { Map<Id, Decimal> mAccAmount = new Map<Id, Decimal>(); //Iterate through each Order for(Order o : Trigger.new) { Decimal d = mAccAmount.get( o.AccountId ); d += o.TotalAmount; mAccAmount.put( o.AccountId, d ); } List<Account> lAccs = [SELECT Id, Chiffre_d_affaire__c FROM Account WHERE Id = :mAccAmount.keySet()]; //Iterate through each List of Accounts for(Account acc : lAccs){ acc.Chiffre_d_affaire__c = acc.Chiffre_d_affaire__c + mAccAmount.get(acc.Id); } update lAccs; }
check for syntax error. i ahve not tested it.
basically you have to check that your accountid which is acting as key in map is present or not then proceed accordingly.
All Answers
looks like it is null so Decimal d is assigned to null at line 7.
I see, the value of Decimal is Null.
I did a System.debug('Decimal value ' +d);
Log: 12:54:38:004 USER_DEBUG [8]|DEBUG|Decimal value null
But how do I populate Decimal?
you need to populate it. only after that you can get value from it.
may i know what mAccAmount should store?
check for syntax error. i ahve not tested it.
basically you have to check that your accountid which is acting as key in map is present or not then proceed accordingly.