+ Start a Discussion
sindicaresindicare 

Trigger Help

Hi,

 

Can any one provide a sample code to perform the Rollup Sum() Trigger.

Thanks
Navatar_DbSupNavatar_DbSup

Hi,

 

Aggregate functions allow you to roll up and summarize your data for analysis


Try the below code snippet as reference

trigger DealTrigger on DealInterest__c (before update,before insert)
{

DealInterest__c di;
Deal__c dd;
AggregateResult[] lid;
String str;

for(DealInterest__c d:Trigger.New)
{
dd=[Select Name From Deal__c where id=:d.DealL__c ];

lid=[Select sum(DealNum__c)num from DealInterest__c where DealL__c=:d.DealL__c ];
if(lid[0].get('num')==null)
{
d.DealNum__c=1;
d.IntID__c=d.DealL__c+'-000'+String.valueof(1);

}

}
}

For more detail follow the below link
http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_soql_select_agg_functions.htm

abhishektandon2abhishektandon2

Why you want to it from Trigger, you van jsut create a roll up summery field.

 

Any how if you wnat to do it from trigger

then use 

 List<AggregateResult> aggResult= [Select sum(field name) <alias o filed> From Object WHERE field_name=:?];