Activity Forums Salesforce® Discussions Can we update the same record in After Trigger context. Is there any way or workaround?

  • Can we update the same record in After Trigger context. Is there any way or workaround?

    Posted by Saurabh on April 7, 2017 at 1:29 pm

    How to update  the same record in After Trigger context.

    Manpreet replied 7 years ago 2 Members · 1 Reply
  • 1 Reply
  • Manpreet

    Member
    April 7, 2017 at 1:42 pm

    Hi saurabh,

    You can do something like this :

    trigger AccNameUpdate_And_ContactInsert on Account (before insert ,after insert) {

    List<Contact> lst = new List<Contact>();

    if(Trigger.isBefore && Trigger.isInsert ){
    for(Account acc : TRigger.New){
    acc.Name = 'Test'+ acc.Name ;

    }
    }

    if(Trigger.isAfter && Trigger.isInsert ){
    for(Account acc : Trigger.New){

    Contact c = new Contact();
    c.lastName='Singh';
    c.AccountId = acc.Id;
    lst.add(c);
    }
    insert lst;
    }

    Thanks.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos