Suppose you have objects Customer and Invoice. Invoice has a lookup to to Customer, which means each Customer can have to multiple Invoices. Considering that:

  • Multi currency is enabled.
  • Customer can be set to any of the available currencies.
  • Invoice can be set to any currency, independently from it's customer.
  • Invoice has a Currency field with its value.

I need to sum the value of each customers invoices in an Apex Trigger, doing appropriate conversions of the currency of each Invoice to the Customers currency.

I have this working using number fields, but now need it to work with currency fields.

Is this possible at all without needing anything crazy (such as calling external services to get exchange rates)?


Currency values are converted to the "corporate currency" at the database level. This means that, as long as the currency is set correctly for each record, and multicurrency is configured correctly for each currency, all you need to do is use the normal math operators: +, -, /, *. They're already in a common base currency value, so all you need to do is simple math.

If you've ignored the actual multicurrency feature and built your own crazy scheme, then you're going to have to write your own custom logic. Ignoring the standard feature is something you should do at your own peril. Multicurrency is designed to make the developer's life as simple as possible.

  • Thanks, this is actually the kind of answer I was looking for. As I haven't worked with currencies before, I didn't know they worked like this, with "overridden" operators that convert on their own. And no, I haven't built any crazy scheme, because I was hoping SF would have some standard functionality to cover this. Which turns out be to true, thankfully. Aug 8 '18 at 10:28
  • @Henrique Yeah, the multicurrency feature has saved me a lot of trouble in the past. I just wish the documentation was more explicit about it.
    – sfdcfox
    Aug 8 '18 at 10:31

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.