ads

Friday, 17 August 2018

update parent records when task created or updated

Sample Trigger:

trigger  TaskParentUpdate  on Task (after insert, after update) {

    Set < Id > setIds = new Set < Id >();


if(IsInsert || IsUpdate) {

    for ( Task tsk : trigger.New) {
        if ( tsk.WhatId.getSobjectType().getDescribe().Name == 'Accounts' )
        setIds.add(tsk.WhatId);
    }
   
}

    List<Account> lAccount = [Select Id,description From Account where Id IN:setIds];


  List<Account> UpdateAccount = new List<Account>();

    for(Account a:lAccount){
        a.description = 'Description Updated';
       UpdateAccount.add(a);

   }


  update UpdateAccount;


}

No comments:

Post a Comment