function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
KtobenerKtobener 

Attempting to use dynamic apex to set a custom object's currencyisocode

Hello!

 

I've been working on adding multi-currency support to a future app exchange product, and I'm having trouble finding the right logic to set my quote.currencyisocode dynamically.

 

 

first I tried:

sobject oppriso = quote.getSObject('Opportunity__r.CurrencyIsoCode');

quote.putObject('CurrencyIsoCode', oppriso);

 

then:

sobject oppriso = quote.getSObject('Opportunity__r').get('CurrencyIsoCode');

quote.putObject('CurrencyIsoCode', oppriso);

 


And then I thought maybe:

quote.putObject('CurrencyIsoCode',(string)quote.getSObject('Opportunity__r').get('CurrencyIsoCode'));

 

 

All of these methods return compile errors relating to sobject/string type problems. I spent all night working on this, so maybe I'm just snowblind so to speak. Is there a dynamic method for putting a string into a string field on an object?

Best Answer chosen by Admin (Salesforce Developers) 
KtobenerKtobener

You were absolutely right. Snowblind indeed.

 

The final working code ends up being:

quote.put('CurrencyIsoCode',(string)quote.getSObject('Opportunity__r').get('CurrencyIsoCode'));

 

Thanks a bunch!

All Answers

bob_buzzardbob_buzzard
According to the Apex docs, you should be able to simply use 'put' as opposed to 'putObject'.
KtobenerKtobener

You were absolutely right. Snowblind indeed.

 

The final working code ends up being:

quote.put('CurrencyIsoCode',(string)quote.getSObject('Opportunity__r').get('CurrencyIsoCode'));

 

Thanks a bunch!

This was selected as the best answer