1

I created a code that copies the value of the source currency field ( object A ) to destination currency field ( Object B )

What happens is that this code

Decimal A = A.currencyfield;

B.field = A;

copies the exact numeric value but changes the currency of the destination field to the user's default currency.

example: source is EUR 1.00 but the destination becomes US$1.00. it doesnt either convert the value or keep the currency format.

Any idea how to keep the currency during field update?

Appreciate your input on this.

Thanks in Advance.

2 Answers 2

2

Once you enable multi-currency, every sObject gets an OOB field called currencyIsoCode

By default, when an object is created via an insert DML operation (e.g. user clicks Save on a new record), the currencyIsoCode of the new object will be the user's default currency (some exceptions to this such as OpportunityLineItem which will use the currency of the parent Opportunity)

So, when creating ObjectB, you need to also copy A's currency to B:

b.currencyIsoCode = a.currencyIsoCode;
-1

Check out the following links:

  1. What is a concise function that formats a (String) decimal into a currency format in Apex?
  2. How to force number format on apex:inputText
  3. http://www.cloudjedi.com/blog/salesforce/formatting-numbers-or-dates-with-visualforce/
1
  • I am not trying to convert the currenct field into a text. I just want to keep the currency of the specific currency field when a trigger populates the destination field.
    – JOE
    Dec 10, 2014 at 13:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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