+ Start a Discussion
pavan mithunpavan mithun 

Hi All, how to Write a trigger on opportunity so that it should roll-up Opp field Values Only for particular Record Type (Say Record Type A not for Record Type B) using LREngine

Hi Pavan,
RecordType recordType = [ SELECT ID FROM RecordType Where Name = ' RecordType Name'  LIMIT 1 ];
AggregateResult[] groupedResults
  = [SELECT CampaignId, AVG(Amount)
      FROM Opportunity
      GROUP BY CampaignId WHERE RecordTypeId = :recordType.Id ];
for (AggregateResult ar : groupedResults)  {    
	System.debug('Average amount' + ar.get('expr0'));