You need to sign in to do that
Don't have an account?

Need help in Trigger
After saving the Account record, I want to capture the ID of the Account in 'Record_Number__c' field of Account. How to write this trigger.
My try was as:
trigger CopyID on Account (after Insert) {
List <Account> acclst = new List <Account>();
for(Account acc : Trigger.New){
acc.Record_Number__c = acc.Id;
}
}
But use of afetr event on Triggere,New , while changing the field will give : System.FinalException: Record is read-only: error.
How to modify the code to sufice the reqment?
Do this in formula field.
That is the best practice.
Never write trigger for this things.
Create a formula field with return type as text and choose ID as the Insert Field and save.
In trigger the problem is you are using after insert and then assigning it again without using update statement.
It is not a good practice to use this.
If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.
Thanks
Okay. I got it !!!
Record_Number__c is a Auto Number field you can't push anything to that field. It always remains readonly field. System Automatically generates numbers for that field.