+ Start a Discussion

Need Urgent Help please .....

Hi All,


Please help me anyone aware of the issue.

 I have a requirement. I have a field like Opportunity currency(standard field) in Opportunity object. After created the opportunity nobody are able to edit the currency field. because that Opportunity have some products.  So we are try to add some code that does this for them - e.g. a visual force page where they choose the new currency, and the controller deletes the products, changes the currency and then adds the products back again. and based on the Opportunity currency many fields are caliculating internally,that is the issue what i am facing.


anybody please provide sample code to resolve the above issue. I am new to salesforce development . can you please provide the trigger logic if possible. Ex: trigger deleteandaddproducts on Opportunity (before update,after update) { // Need logic to delete the Opportunity products when before update // and add deleted opportunity records into opportunity after update } Anybody please help me out...... Thanks,




"when you change the currency on a record via the browser, currency amounts on that record are not updated. Thus, if you change the currency of an opportunity whose amount is 5000 from USD to EUR, the amount remains 5000


However, currency amounts are converted when you change record currency via tools that use the Saleforce API, such as the Data Loader. This means that changes to the currencies of records made via the data loader will cause a mass recalculation of any currency fields on those records. (knowledge article num:000005014)" - That means if you change the record currency through code, for example from 5000USD to EUR, the record amount will be 3700 EUR (given change rate EUR/USD = 0,74). This is the native behavior. A workaround could be to copy the amounts before changing the record currency and paste them after currency change.

Hope this helps.




Here are some tips:


1. Use an after update trigger that does its work if currency has changed and products (OpportunityLineItems = OLI) exist


2. The trigger will need to read all the OLI  and especially the pricebook2Id and Product2id fields as they are needed in step 3


3. You will then need to locate the corresponding pricebookEntry records for the compound key = pricebook2id + product2Id + newCurrency


4. Then, go through the list you saved in step 2 but swap in the new pricebookentryIds and insert the records



and all of this should be bulkified as it is possible that a batch operation could change the currency of >1 Opportunity in the same transaction