+ Start a Discussion
kirankumarreddy punurukirankumarreddy punuru 

how to convert other currency to usd

Hi i need to check the currency for an object and have to set the currency of a field  to usd based on condition like this

if(opp.CurrencyIsoCode !='USD')
{
here i need to convert other currency to usd for a field called as salesprice__c

}
 
salesforce mesalesforce me
Hi.

When exchange rates are updated they're stored in the CurrencyType object, so do something like this:

 

1 list<CurrencyType> c = [SELECT ISOCode, ConversionRate FROM CurrencyType WHERE IsActive=TRUE];<br>

 

So you have a list of currently active currencies and their exchange rate.  To get currency values into your org's currency, just divde the value by that currency's exchange rate.  for example:

 

1 for(integer i = 0; i< c.size(); i++){<br> if(Opp.CurrencyISOCode == c[i].ISOCode){<br>  convertedCurrency = Opp.Amount / c[i].ConversionRate;<br> }<br>}




                                              OR
 
OR(
AND( ISPICKVAL (CurrencyIsoCode , "USD"),
ISPICKVAL( Alternative_NST_Type__c , "8k - 8pct"),
Service_Incremental_Discount__c > 8000),
AND( ISPICKVAL (CurrencyIsoCode , "EUR"),
ISPICKVAL( Alternative_NST_Type__c , "8k - 8pct"),
Service_Incremental_Discount__c > 5840),
AND( ISPICKVAL (CurrencyIsoCode , "GBP"),
ISPICKVAL( Alternative_NST_Type__c , "8k - 8pct"),
Service_Incremental_Discount__c > 5160))

 
                                                                   OR



Double conversionRate = [SELECT conversionrate FROM currencytype WHERE isocode =: sISO LIMIT 1].conversionRate;


 
kirankumarreddy punurukirankumarreddy punuru
Thanks, I need to write that condition in trigger
Abhishek BansalAbhishek Bansal
Hi,

Please use the below trigger to convert slaes price to USD :
trigger convertToUSD on Opportunity (before insert, before update){
	List<CurrencyType> currencyTpyeList = [select id,IsoCode,ConversionRate from CurrencyType where isActive = true] ;
	Map<String , Decimal> isoWithRateMap = new Map<String, Decimal>();
	for(CurrencyType c : currencyTpyeList) {
        isoWithRateMap.put(c.IsoCode , c.ConversionRate) ;
	}
	
	for(Opportunity opp : trigger.new){
		if(opp.CurrencyIsoCode != 'USD' && isoWithRateMap.containsKey(opp.CurrencyIsoCode)){
			opp.salesprice__c = opp.salesprice__c / isoWithRateMap.get(opp.CurrencyIsoCode);
		}
	}
}
Please use the conversion code in your trigger accordingly.
Let me know if you need more help on this.

Thanks,
Abhishek
 
Sourabh KhoslaSourabh Khosla

@Abhishek: 

How do I default to EUR instead of USD?