function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
BDouglasBDouglas 

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? 

 

 

jkucerajkucera

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.

jkucerajkucera

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