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
paul.magpaul.mag 

Set Currency Picklist value

Hi there, we have a custom object "Invoice Request" that has a lookup relationship with Opportunity. I want the standard currency picklist  field on the Inoice Request record set to whatever value is in the standard currency picklist field on the Opportunity record. This should only happen on creation of the Invoice Request record, users should be able to invoice in whatever currency they choose.

 

Thanks in advance

 

Paul

 

Best Answer chosen by Admin (Salesforce Developers) 
vagishvagish

Hi Paul,

 

I would have written a pretty simple trigger as below:

I am assuming relation name is Opportunity__c in Invoice_request__c object, you can modify this name as you might have used:

 

trigger UpdateCurrency on Invoice_Request__c (before insert) {
    List<Id> opportunityIds = new List<Id>();
    Map<Id, String> oppIdCurrencyCode = new Map<Id, String>();
    for(Invoice_Request__c ir : System.Trigger.new) {
        opportunityIds.add(ir.opportunity__c);
    }
    for(Opportunity opp : [Select CurrencyIsoCode from Opportunity where Id in: opportunityIds]) {
        oppIdCurrencyCode.put(opp.Id, opp.CurrencyIsoCode);
    }
    for(Invoice_Request__c ir : System.Trigger.new) {
        ir.CurrencyIsoCode = oppIdCurrencyCode.get(ir.opportunity__c);
    }
}

 

Please post if you found any better approach or have any questions.

 

-Vagish

All Answers

Bhawani SharmaBhawani Sharma
There is a standard field in salesforce called CurrencyISOCode. You can put it on your layout.
paul.magpaul.mag

It is on the layout but when you create a new Invoice Request the CurrencyISOCode defaults to the users currency and not the opportunity currency, I also cannot do a workflow field update either hence the need to use a trigger ( I think)

 

Thanks

 

Paul

Bhawani SharmaBhawani Sharma
You can simply override your new button with a VF page. This page will pick the currency data from opportunity record and will redirect user to again on the new page with a new query string parameter like
/001/e?currencyIsocode=USD&no.override=1

paul.magpaul.mag

Thanks for that, doesn't sound that simple to me ;-) but i'll take your word for it

 

 

Bhawani SharmaBhawani Sharma
This will not exactly the same you need to do, but it can help a lot.
http://www.salesforce.com/docs/developer/cookbook/Content/vf_conditional_page.htm
vagishvagish

Hi Paul,

 

I would have written a pretty simple trigger as below:

I am assuming relation name is Opportunity__c in Invoice_request__c object, you can modify this name as you might have used:

 

trigger UpdateCurrency on Invoice_Request__c (before insert) {
    List<Id> opportunityIds = new List<Id>();
    Map<Id, String> oppIdCurrencyCode = new Map<Id, String>();
    for(Invoice_Request__c ir : System.Trigger.new) {
        opportunityIds.add(ir.opportunity__c);
    }
    for(Opportunity opp : [Select CurrencyIsoCode from Opportunity where Id in: opportunityIds]) {
        oppIdCurrencyCode.put(opp.Id, opp.CurrencyIsoCode);
    }
    for(Invoice_Request__c ir : System.Trigger.new) {
        ir.CurrencyIsoCode = oppIdCurrencyCode.get(ir.opportunity__c);
    }
}

 

Please post if you found any better approach or have any questions.

 

-Vagish

This was selected as the best answer
sushant sussushant sus
hi ,
i think u can use workflow for this also ..

in this u have to use if and include in formula value ..

try this it is easy
paul.magpaul.mag

Thanks for that it works well. The only question I would ask is it is possible to update the currency field on creation of the invoice record. It changes on save but this may cause some user confusion.

 

Many Thanks

 

vagishvagish

Glad to know that it solved your purpose.

The way you are asking is only possible with the approach as Tech Force posted above. You will have to override the new button of list view and then do the url hack.

paul.magpaul.mag

No worries, will just move the field to be less prominent and advise the users. Thanks again