You need to sign in to do that
Don't have an account?
BDouglas
Not able to use aggregate function Sum on opportunity amount.
I get save error: Illegal assignment from String to Decimal for the following code in a trigger using API version 18.0
trigger updateContactTotalSales on Opportunity (after insert, after update) { AggregateResult[] opportunityTotal = [SELECT SUM(Amount) FROM Opportunity]; }
Anyone know why?
Stab in the dark - are you using multi-currency for your org? You may need to include currency conversion for Amount.
Also, wouldn't the result be a single value, not an array? You didn't include a GROUP BY to say how to subtotal the amount, so the result should be just 1 record, not an array.
Ok - I'm wrong on the 2nd part - you do need the [ ]. Not sure on the error though.
http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_SOQL_agg_fns.htm?SearchType=Stem&Highlight=AggregateResult