I need help on storing currency fields with their currencyisocode while working with triggers
for(sObject o : newRecordsFromTrigger){
Capture_Field_History__c fh = new Capture_Field_History__c();
fh.NewValue__c = String.valueOf(o.get(fieldName)); // output is 100.00
fh.OldValue__c = String.valueOf(oldObject.get(fieldName)); // output is 50.00
list.add(fh);
}
In above code if the trigger is firing from Opportunity having Amount changed from 50.00 to 100.00 and fieldName is Amount then I will have 100.00 in NewValue instead I want it to be stored as ISO_CODEvalue i.e. USD 100.00 .
I tried using below code to format but it didn't work :-
fh.NewValue__c = String.valueOf(((Decimal)(o.get(fieldName))).format()); // output is 100
I know we can achieve it using SOQL as below but in this case of triggers I am avoiding using SOQL
Opportunity opp = [SELECT Id, format(Amount) amt FROM Opportunity LIMIT 1] // opp.get('amt') = USD 100.00
o.get('CurrencyIsoCode')
in your loop?