You need to sign in to do that
Don't have an account?
SFDC Dummy
After Trigger not saving
Hi Guys
How to create calculation after insert trigger value
after firing the trigger ,how i will created calaculation on particalar value with the help of trigger
error
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger realtime2 caused an unexpected exception, contact your administrator: realtime2: execution of AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.realtime2: line 10, column 1
How to create calculation after insert trigger value
after firing the trigger ,how i will created calaculation on particalar value with the help of trigger
trigger realtime2 on BankBook__c (after insert){ List<BankBook__c> bnkBookListToUpdate=new List<BankBook__c>(); for(BankBook__c bkObj:[SELECT Id,New_Closing_Bal__c,New_Related_Bank_Acc__c,Debit__c,Credit__c FROM BankBook__c WHERE Id IN :Trigger.new]) { double s = bkObj.New_Related_Bank_Acc__c; //copy the notes to a string object double s1 = bkObj.Debit__c; double s2 = bkObj.Credit__c; bkObj.New_Closing_Bal__c=s-s1+s2 ; // bkObj.New_Closing_Bal__c= bkObj.New_Related_Bank_Acc__c; bnkBookListToUpdate.add(bkObj); } try{ update bnkBookListToUpdate; }catch(DMlException de ){ System.debug(de ); } }
error
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger realtime2 caused an unexpected exception, contact your administrator: realtime2: execution of AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.realtime2: line 10, column 1
Can you try this
Or in Before insert also you can do it will save your dml.
Thanks
Sunil
For this either you are create a formula field on BankBook object or you can do the calculations on the before insert trigger like this:
As you are updating the same record so it ir preferred to use before insert trigger.
trigger realtim2 on BankBook__c( before insert )
{
for( BankBook__c b : trigger.new )
{
Decimal s = ( b.New_Related_Bank_Acc__c != null ? b.New_Related_Bank_Acc__c : 0.00 );
Decimal s1 = ( b.Debit__c != null ? b.Debit__c : 0.00 );
Decimal s2 = ( b.Credit__c != null ? b.Credit__c : 0.00 );
b.New_Closing_Bal__c = ( s - s1 + s2 );
}
}
Thanks,
Neetu
Try this one and select as best answer if it helps you. So it will be easy for others to search easily.
You mean to say OB__c is a debit object and it needs to be removed multiple time from the BankBook__c object?
Thanks,
Neetu