You need to sign in to do that
Don't have an account?
Nejib Essouri
Trigger that affects an old value from one record to another created
Hi guys, I would asign the old value of "stock_actuel__c" to the new field when a record is created. I develop this trigger. The problem is that when I insert a record I have an exception nullpointer:
MyTigger:
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger InvoiceStock caused an unexpected exception, contact your administrator: InvoiceStock: execution of AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.InvoiceStock: line 3, column 1
MyTigger:
trigger InvoiceStock on Tissus__c (after insert, after update, after delete) { for(Tissus__c tnew : Trigger.New) for(Tissus__c told : Trigger.Old){ if(tnew.Name == told.Name) tnew.stock_actuel__c = told.stock_actuel__c ; } }the Exception:
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger InvoiceStock caused an unexpected exception, contact your administrator: InvoiceStock: execution of AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.InvoiceStock: line 3, column 1
Please try with the below code :
Let me know if you have any issue.
Thanks,
Abhishek
All Answers
Try the following code it will be work.
Let me know if you have any question regarding this.
Thanks,
Vijay
I try the code below and the same exception is there..
This is how your code ideally should be
Kindly mark it as an answer if that works.
Let me know if you face any issue.
Thanks,
Vijay
Please give this a try: Thanks!
You are getting the exception because you are trying to update the same record in after update context.
In after update context the record is considered to be Read-Only so you cannot update any value of the same record
Please try with the below code: Let me know if you have any issue.
Thanks,
Abhishek
i try your code, the exception is not appeared but the new firld is not uodated.
May be you are missing something in your testing here.
If it is possible for you than please contact me on :
Gmail : abhibansal2790@gmail.com
Skype : abhishek.bansal2790
Please try with the below code :
Let me know if you have any issue.
Thanks,
Abhishek