You need to sign in to do that
Don't have an account?
Al Sugarman
Need help on a trigger converting currency to USD
I created a number field that I am trying to populate with the USD amount of a currency field on opportunities. I have tried two methods but still the field display only the currecy thet the opportunity is in...any help is appreciated...
Method 1
trigger convertcurrency on Opportunity (before insert, before update) {
for(Opportunity o :trigger.new){
Boolean isChanged = false;
if(trigger.isUpdate && o.Reporting_Total__c != trigger.oldMap.get(o.Id).Reporting_Total__c){
isChanged = true;
{
Opportunity[] opps = [select convertCurrency(Reporting_Total__c) from Opportunity where Id = :o.Id];
o.Reporting_Total_in_USD__c = o.Reporting_Total__c;
}
}
}
}
===============================================
Method 2
trigger convertcurrency on Opportunity (before insert, before update) {
for(Opportunity o :trigger.new){
Boolean isChanged = false;
if(trigger.isUpdate && o.Reporting_Total__c != trigger.oldMap.get(o.Id).Reporting_Total__c){
isChanged = true;
{
For (AggregateResult[] opp : [select name, SUM(Reporting_Total__c) rt from Opportunity where id = : o.id group by Name ])
for(AggregateResult ar : opp){
o.Reporting_Total_in_USD__c = o.Reporting_Total__c;
}
}
}
}
}
Method 1
trigger convertcurrency on Opportunity (before insert, before update) {
for(Opportunity o :trigger.new){
Boolean isChanged = false;
if(trigger.isUpdate && o.Reporting_Total__c != trigger.oldMap.get(o.Id).Reporting_Total__c){
isChanged = true;
{
Opportunity[] opps = [select convertCurrency(Reporting_Total__c) from Opportunity where Id = :o.Id];
o.Reporting_Total_in_USD__c = o.Reporting_Total__c;
}
}
}
}
===============================================
Method 2
trigger convertcurrency on Opportunity (before insert, before update) {
for(Opportunity o :trigger.new){
Boolean isChanged = false;
if(trigger.isUpdate && o.Reporting_Total__c != trigger.oldMap.get(o.Id).Reporting_Total__c){
isChanged = true;
{
For (AggregateResult[] opp : [select name, SUM(Reporting_Total__c) rt from Opportunity where id = : o.id group by Name ])
for(AggregateResult ar : opp){
o.Reporting_Total_in_USD__c = o.Reporting_Total__c;
}
}
}
}
}
You can use formula field or process builder(new tool) to achieve this.
Where are you geting conversion formula from ? I assume Reporting_Total__c don't have USD value.
Regards,
Rahul
I have tried a formual field, both as currency and number. I was unable to use the convertcurrency() function in either formula.but got the just adding the convertcurrency() function retunred the Error: Incorrect parameter type for function 'convertcurrency()'. Expected Currency, received Number...even though this is a currecy field.
I have also tried the following in a trigger
if(currencies.get(o.CurrencyIsoCode).ConversionRate != null){
o.Reporting_Total_in_USD__c = o.Reporting_Total__c / currencies.get
(o.CurrencyIsoCode).ConversionRate;
This gets me closer but if the close date on the opportunity is any other month than the current month the values do not match.
Thanks,
Al .
convertcurrency() is used when multicurrency is enabled. Is that enabled and set USD and local currency in your system?
Please check link below.
http://www.salesforce.com/us/developer/docs/soql_sosl/Content/sforce_api_calls_soql_querying_currency_fields.htm
Could you please share forumla field and formula you wrote to convert Your currency to USD?
Thanks,
Rahul
Thanks,
Luis