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
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? 

Smitha KumariSmitha Kumari
@Abhishek

I am tring the same with Advance currency management, 

In my Requirement the values should get picked from the "Manage dated currency exchange rate" ,


My Default currency is INR, I have enabled multiple currecny, I want to retrive all the conversion values based on months, I have
Defined it in the Manage Dated Exchange Rates, 

In the Trigger I am fetching the Manage Dated Exchange Rates through an api called DatedConversionRate

I am using the SOQL query, 

SELECT Id, IsoCode, ConversionRate, StartDate, NextStartDate FROM DatedConversionRate

Now my requirement - Based on the Month End Date the conversionvalues should pickup for EUR or USD, The conversion rate should show in INR

I have modified the trigger, but i am not able to get the values
 
trigger Convertedcurrency on Dated_Currency__c (before insert,before update) {
    
    List<DatedConversionRate> currencyTypeList = [SELECT Id, IsoCode, ConversionRate, StartDate, NextStartDate FROM DatedConversionRate ORDER BY NextStartDate DESC];
    
    Map<String , Decimal> isoWithRateMap = new Map<String, Decimal>();
    
    for(DatedConversionRate c : currencyTypeList){
        
        isoWithRateMap.put(c.IsoCode,c.ConversionRate);
    }
    
    for(Dated_Currency__c ce: trigger.new){
        
        if(ce.Month_End_Date__c!=null && ce.CurrencyIsoCode != 'EUR' && isoWithRateMap.containsKey(ce.CurrencyIsoCode)){
            
            ce.Converted_Value__c = ce.Amount__c/ isoWithRateMap.get(ce.CurrencyIsoCode);
        }
        
        if(ce.Month_End_Date__c!=null && ce.CurrencyIsoCode != 'USD' && isoWithRateMap.containsKey(ce.CurrencyIsoCode)){
            
            ce.Converted_Value__c = ce.Amount__c/ isoWithRateMap.get(ce.CurrencyIsoCode);
            
        }
    }
}

Any help would be very helpfull