2

So Im looking at this page: https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_querying_currency_fields.htm

It really just says to use convertCurrency to get a currency in the users currency.

But objects can have a currency. So How do I get the value of the field in the user currency and the object currency in the same query?

1 Answer 1

2

I believe that's their third snippet?

SELECT Amount, FORMAT(amount) Amt, convertCurrency(amount) convertedAmount,
FORMAT(convertCurrency(amount)) convertedCurrency FROM Opportunity where id = '006R00000024gDtIAI'

You can reselect the currency column multiple times, and give it aliases (as above, with Amount, Amt, and convertedAmount) where the first is the original stored amount, the second being formatted nicely, and the last being in the user's currency.

6
  • Cool, I misunderstood that. Is there any way to check this in the developer console. When I try to use the alias, it just doesnt show the field being aliased. Commented Jun 5, 2019 at 16:02
  • 1
    When I use the query editor in the developer console, the query runs just fine, but the headers don't show the alias. E.g. SELECT count(ID) ids, count(ContentDocumentId) names FROM ContentVersion works ok. That works fine in the execute anonymous block too, like so: ` List<SObject> stuff = [SELECT count(ID) ids, count(ContentDocumentId) names FROM ContentVersion]; System.debug('ids: ' + stuff[0]); ` Results in 10:14:28:007 USER_DEBUG [2]|DEBUG|ids: AggregateResult:{ids=181, names=181} Not sure offhand what you'll have to do about casting the thing into something useful...
    – pmiller3
    Commented Jun 5, 2019 at 16:15
  • When I run the query Select Id, FORMAT(convertCurrency(Test_Currency__c)) convertedCurrency From Test_Object__c in the query editor I only get the Id back Commented Jun 5, 2019 at 16:16
  • Is there a value in Test_Currency__c? What's the result of Select Id, Test_Currency__c, FORMAT(convertCurrency(Test_Currency__c)) convertedCurrency From Test_Object__c?
    – pmiller3
    Commented Jun 5, 2019 at 16:18
  • Yeah there is a value in there. It works fine with a debug from the Anonymous Window. I get the results I expect back. That will do I guess. There are 3 Test_Objects__c in the db. Each has a currency field with a value. Commented Jun 5, 2019 at 16:21

You must log in to answer this question.

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