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)?

1 Answer 1


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. Commented Aug 8, 2018 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
    Commented Aug 8, 2018 at 10:31
  • @sfdcfox I was trying to do simple calculation ( Using apex trigger ) i.e. adding 3 opportunity amount in different currency and save that to Account. It seems the currency conversion not working automatically. Opp 1 : 5 USD, Opp2 : 10 USD, Opp3 : 20GBP, Accout shows 35 USD. I have currency conversationr rate setup like this 1 USD = 1.5 GBP. Do you know what could a possible reason behind this? Commented Dec 1, 2023 at 11:06

You must log in to answer this question.

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