+ Start a Discussion
Gonzalo ParraGonzalo Parra 

Any way to set the CurrencyIsoCode of an OpportunityLineItem before inserting it?


We are in the process of enabling MultiCurrency support in our org and have a custom page to add / edit products in the opportunity (for a bunch of reasons that do not really matter for this question), this customization has worked well for years.

We load current OpportunityLineItems to an array and then the user adds / modifies / removes as needed, then when the user clicks on save we just do an Upsert of the array and all changes are saved, so if the user closes without saving no changes are commited...

The problem we are having is that when after enabling Multi-Currency, existing products show fine but new products show the wrong currency. I tracked this down to an empty CurrencyIsoCode for any new OpportunityLineItem which is a non writtable field that is calculated out of the opportunity CurrencyIsoCode, this field seems to only get populated server side when you actually insert the OpportunityLineItem.

So, is there any way to set this field for new OpportunityLineItems in memory before inserting?

We added a workaround where we actually insert the OpportunityLineItems, query the DB to refresh the CurrencyIsoCode field and then delete it from the DB in the next line just so we can insert a complete recoed in the in memory array, this works but is of couse a horrible solution IMHO...

Any suggestion or workaround?