0

I am working in an org that has multi currency enabled, and am trying to query out the biggest opportunities per Account, where the opp is over 10,000 GBP or USD.

I was hoping to use something like this:

Select AccountId, MAX(Amount) FROM Opportunity WHERE Amount > USD10000 OR Amount > GBP10000 and CloseDate = LAST_N_YEARS:3 GROUP BY AccountId

If I query without specifying a currency, then the SOQL results are returned converting the amount to my locale. So I get USD 10,000 opportunities returned with the amount in GBP (which is around GBP£7k). Reason I need the true amount values, is I then want to loop over the values in apex to update some records.

1

According to the documentation you can use it like that as long as you don't use it with aggregated results (so not HAVING MAX(Amount) > GBP10000)

So I'd say you can just have

SELECT AccountId, MAX(Amount)
FROM Opportunity 
WHERE 
    (Amount > USD10000 OR Amount > GBP10000) AND 
    CloseDate = LAST_N_YEARS:3 
GROUP BY AccountId

(note the difference in brackets)

| improve this answer | |
  • Perfect thanks! I tried brackets myself, but was putting them in the wrong place, I had tried ... WHERE (Amount > USD10000) OR (Amount > GBP10000) AND CloseDate ... – developer__c May 6 at 9:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.