You need to sign in to do that
Don't have an account?
Todd B.
Moving a Trigger to a Class
Hello All,
I recently designed a trigger to update a Goals/Forecast custom object I built called Financial_Planning__c. Basically, on the "before update" action of the object, the trigger goes out and finds all the Closed Won opportunities for that division and updates a field on the Financial_Planning__c object.
<pre>
trigger FinancialPlanningTrigger on Financial_Planning__c (before update) {
List<Date> dtStart = new List<Date>();
List<Date> dtEnd = new List<Date>();
List<String> strSBU = new List<String>();
Double fpAmount = 0 ;
String strname;
for(Financial_Planning__c fp : trigger.new){
dtStart.add(fp.period_start_date__c);
dtEnd.add(fp.period_End_date__c);
strSBU.add(fp.Division__c);
strname = fp.division__c + ' - (' + fp.Revenue_Type__c + ')';
}
List<aggregateResult> fpresults = [select Sum(amount) Total from Opportunity
where IsWon=True
And Contract_Start_Date__c >= :dtStart
And Contract_Start_Date__c <= :dtEnd
And SBU__C in :strSBU];
for (AggregateResult ar : fpresults ) {
fpAmount = (Double)ar.get('Total');
}
for(Financial_Planning__c fp : trigger.new){
fp.Realized_Revenue_Actual__c = fpamount;
fp.name = strname; // field on which Task count and event count needs to be updated
}
}
</pre>
Based on some info I heard at a developers group, I want to take the code out of the trigger and put it in a class, then have the trigger call the class? How would I do that? I just figured out how to create a trigger, and have not really mastered classes yet.
I recently designed a trigger to update a Goals/Forecast custom object I built called Financial_Planning__c. Basically, on the "before update" action of the object, the trigger goes out and finds all the Closed Won opportunities for that division and updates a field on the Financial_Planning__c object.
<pre>
trigger FinancialPlanningTrigger on Financial_Planning__c (before update) {
List<Date> dtStart = new List<Date>();
List<Date> dtEnd = new List<Date>();
List<String> strSBU = new List<String>();
Double fpAmount = 0 ;
String strname;
for(Financial_Planning__c fp : trigger.new){
dtStart.add(fp.period_start_date__c);
dtEnd.add(fp.period_End_date__c);
strSBU.add(fp.Division__c);
strname = fp.division__c + ' - (' + fp.Revenue_Type__c + ')';
}
List<aggregateResult> fpresults = [select Sum(amount) Total from Opportunity
where IsWon=True
And Contract_Start_Date__c >= :dtStart
And Contract_Start_Date__c <= :dtEnd
And SBU__C in :strSBU];
for (AggregateResult ar : fpresults ) {
fpAmount = (Double)ar.get('Total');
}
for(Financial_Planning__c fp : trigger.new){
fp.Realized_Revenue_Actual__c = fpamount;
fp.name = strname; // field on which Task count and event count needs to be updated
}
}
</pre>
Based on some info I heard at a developers group, I want to take the code out of the trigger and put it in a class, then have the trigger call the class? How would I do that? I just figured out how to create a trigger, and have not really mastered classes yet.
I am getting two error messages:
On the trigger line four
<pre>
FinancialPlanningTriggerHandle.beforeUpdate(trigger.new);
</pre>
Save error: Method does not exist or incorrect signature: FinancialPlanningTriggerHandle.beforeUpdate(LIST<Financial_Planning__c>)
Save error: Method does not exist or incorrect signature: FinanicalPlanning.beforeUpdate(LIST<Financial_Planning__c>)
Any thoughts?
with this --