0

There is one object let say Account. In Account I have field called Amount1 Now when I enter value in Amount1 at the time of creation of account record. Account1 field value get updated as'********' , that I am doing by after Insert event.

so for this case I have to go by after insert event. I am doing the same by after insert event but it throws an error 'Field is read only'.

trigger AccountTrigger on Account(after insert)
{
 for(Account currAcc: Trigger.new)
 {
     if(currAcc.Amount1__c != null)
     {
        currAcc.Amount1__c = '**********';

     }      
 }
}
  • Why you need after insert. You should do this in before insert. – Tushar Sharma Jan 24 at 6:11
  • If you want to pre-populate something on Account at the time of insertion then you should use before insert event. You can not modify fields in after insert event, as they are partially saved in database. – sfdc_sk Jan 24 at 6:12
0

After save record you cannot update same object. you have to use before insert on same object.

Note : After Insert/Update/Delete/Undelete event on cross object.

  trigger AccountTrigger on Account(before insert){
   for(Account currAcc: Trigger.new){
      if(currAcc.Amount1__c != null){
           currAcc.Amount1__c = '**********';

       }      
   }
  }
  • Hey thanks for your valuable reply's EACH AND EVERYONE – raja reddy Jan 25 at 4:41
  • I HAVE TO USE AFTER INSERT AND DO THE TASK, IS THERE ANY OTHER WAY TO DO THAT ABOVE REQUIREMENT USING AFTER INSERT – raja reddy Jan 25 at 4:42
  • ANYWAYS YOUR TRIGGER IS WORKING @cloudZigZag – raja reddy Jan 25 at 4:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.