You need to sign in to do that
Don't have an account?
SFDC Dummy
execution of AfterInsert caused by: System.FinalException: Record is read-only:
Hi Friends
How to achieve this type of error in the bellow trigger..
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.FinalException: Record is read-only: Trigger.realtime2: line 8, column 1
How to achieve this type of error in the bellow trigger..
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.FinalException: Record is read-only: Trigger.realtime2: line 8, column 1
trigger realtime2 on BankBook__c (after insert) { for(BankBook__c stuObj:Trigger.new) { stuObj.New_Closing_Bal__c= stuObj.New_Related_Bank_Acc__c; } }
Please try below code:- NOte:- If you want to update the same record then please use before insert
Please check below blog for more information on trigger framwork
http://amitsalesforce.blogspot.in/2015/06/trigger-best-practices-sample-trigger.html
Please check below post:- Salesforce Trigger: When to use Before versus After
http://raydehler.com/cloud/clod/salesforce-trigger-when-to-use-before-versus-after.html
Please let us know if this will help u
Thanks
Amit Chaudhary
Amit and Praveen are correct you can achieve this by changing your event from after to before .
Basically you got this error because incase of after event your record is saved to Database you you can not assign value like before .
In this case you need to have queryu with all ids and need to update .
I think you are clear about your error now .
Try with below code it will solve your probelm as well . Let me knwo if it helps !!
Thanks
Manoj
I have checked your code .You need to modify the 2nd lin elike belwo .
List<BankBook__c> bnkBookListToUpdate=new List<BankBook__c>();
Also if you have to check the null for New_Related_Bank_Acc__c,Debit__c,Credit__c before calulation .
I can suggest you to create a formula fields to calculate this if you have any issue then just check Like belwo
if(bkObj.New_Related_Bank_Acc__c != null && bkObj.Debit__c != null && bkObj.Credit__c != null ){
bkObj.New_Closing_Bal__c=bkObj.New_Related_Bank_Acc__c-bkObj.Debit__c+bkObj.Credit__c;
}
LIke this you can modify but you have to check the null value .