I have an Apex Trigger that will Rollup Summary my Opportunity__c object's three fields: InvoiceTotal__c, InvoiceGrossProfit__c, and InvoiceDiscountAmount__c. The trigger will fire every time an Invoice__c record is updated. I'm able to query and aggregate my Invoice's fields just fine but is not being incorporated correctly with our Multi-Currency.

So, I've added convertCurrency() as shown below.

    for(AggregateResult res : [SELECT OpportunityId__c, SUM(convertCurrency(InvoiceTotal__c))amt1, 
                               FROM Invoice__c  
                               WHERE OpportunityId__c IN :oppIdSet 
                               GROUP BY OpportunityId__c]) {
        oppListToUpdate.add(new Opportunity__c(Id=(Id)res.get('OpportunityId__c'),

        update oppListToUpdate;
    }catch(DmlException de){

Since enabling Multi-Currency, I have combined using SUM and convertCurrency() on my fields. The code is being compiled successfully and no errors are being shown in the Dev Console but when updating records, it is showing this error message (Line 42 is the "res" soql query row):

enter image description here

I'm not familiar with the error at all and have tried adding the queried fields to the GROUP BY but will then show a different error saying those fields cannot be grouped.

Am I missing something? What am I doing wrong exactly?

Thanks for your help.

  • FYI, if(!oppListToUpdate.isEmpty()){ is not necessary, it is okay to DML on an empty list.
    – sfdcfox
    May 1, 2020 at 12:32

1 Answer 1


You're not allowed to use convertCurrency with aggregate functions:

You can’t convert the result of an aggregate function into the user’s currency by calling the convertCurrency() function. If a query includes a GROUP BY or HAVING clause, currency data returned by using an aggregate function, such as SUM() or MAX(), is in the org’s default currency.

The ORA error indicates an unhandled error at the database level, you should report this as a bug to Salesforce Technical Support.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .