1

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.

0

1 Answer 1

2

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)

1
  • 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 ... May 6, 2020 at 9:22

You must log in to answer this question.

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