Grand Parent Update Trigger || Boss Trigger || Complex Trigger for practice from scratch
Trigger Scenario - Update account with number of opportunity Line Items associated.
Жүктеу.....
Пікірлер: 9
@goku69864 ай бұрын
❤ Awesome sir
@Soujisfmails4 ай бұрын
very nice explanation
@prasadchendake9983 ай бұрын
Hii , great explanation . Are you providing any opportunities for experience candidate.
@SunilSharma-ui9sx3 ай бұрын
Hi Sir ,How can I join your Interview preparation batch.
@shubhenduprakash5883 ай бұрын
Can this be done by flow?
@bhi_bandari
3 ай бұрын
yes
@Soujisfmails4 ай бұрын
I modified little bit and included after delete event also trigger CountOfOLIonAcc on OpportunityLineItem (after insert,after delete ) { Set oppIds = new Set(); Set accIds = new Set(); List newoplineList = new List(); newoplineList = (Trigger.isInsert? Trigger.New : Trigger.Old); for(OpportunityLineItem op :newoplineList) oppIds.add(op.OpportunityId); for(Opportunity op :[Select AccountId , id from Opportunity WHERE Id IN :oppIds ]) accIds.add(op.AccountId); List aggroliList = [SELECT Opportunity.AccountId acId, count(id) oliCnt FROM OpportunityLineItem WHERE Opportunity.AccountId IN :accIds group by Opportunity.AccountId]; Map OLIcnt = new Map(); for( AggregateResult oli : aggroliList) { OLIcnt.put( (Id)oli.get('acId'), (Integer)oli.get('oliCnt') ); } List newUpAccList = new List(); for(Id accId:accIds){ Account ac = new Account(Id = accId); if(OLIcnt.containsKey(ac.Id)) ac.Count_OLI__c = OLIcnt.get(ac.Id); newUpAccList.add(ac); } update newUpAccList; }
Пікірлер: 9
❤ Awesome sir
very nice explanation
Hii , great explanation . Are you providing any opportunities for experience candidate.
Hi Sir ,How can I join your Interview preparation batch.
Can this be done by flow?
@bhi_bandari
3 ай бұрын
yes
I modified little bit and included after delete event also trigger CountOfOLIonAcc on OpportunityLineItem (after insert,after delete ) { Set oppIds = new Set(); Set accIds = new Set(); List newoplineList = new List(); newoplineList = (Trigger.isInsert? Trigger.New : Trigger.Old); for(OpportunityLineItem op :newoplineList) oppIds.add(op.OpportunityId); for(Opportunity op :[Select AccountId , id from Opportunity WHERE Id IN :oppIds ]) accIds.add(op.AccountId); List aggroliList = [SELECT Opportunity.AccountId acId, count(id) oliCnt FROM OpportunityLineItem WHERE Opportunity.AccountId IN :accIds group by Opportunity.AccountId]; Map OLIcnt = new Map(); for( AggregateResult oli : aggroliList) { OLIcnt.put( (Id)oli.get('acId'), (Integer)oli.get('oliCnt') ); } List newUpAccList = new List(); for(Id accId:accIds){ Account ac = new Account(Id = accId); if(OLIcnt.containsKey(ac.Id)) ac.Count_OLI__c = OLIcnt.get(ac.Id); newUpAccList.add(ac); } update newUpAccList; }