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

  • 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