top of page

Store related parent record to a Map in Trigger

use case = to store the last opportunity to the account


trigger oppTrg on Opportunity(after insert){

//to map the parent i.e account to the child

Map<Id, Opportunity> accOpp = new Map<Id, Opportunity>();


for(Opportunity op : Trigger.New){

accOpp.put(op.accountId, op);

}


List<Account> accts = [select id, Last_Opp_Name__c from Account where id= :accOpp.keySet()];

for(Account a : accts){

a.Last_Opp_Name__c = accOpp.get(a.id).Name;

}


update accts;

}

Recent Posts

See All

Comments


Post: Blog2_Post

©2020 by SalesforceDemystified. Proudly created with Wix.com

bottom of page