Currency picklist values in VF differ from Standard Layout to VF page

Is there any reason or counter-measure against the fact that Currency picklist values are different on VF pages than on Standard Layouts?

Standard Layout Edit Mode:

enter image description here

VF page with apex:inputField:

enter image description here

Answer

We can fulfill this requirment by our custom describe Sobject call. I would like to provide you the working code/solution for this problem. Code is given below:-

Visualforce page:-

<apex:form >
    <apex:pageBlock title="Currency ISO Code">   
    <apex:pageBlockSection >
        <apex:pageBlockSectionItem >
            <apex:selectList id="countries" value="{!Opportunity.CurrencyIsoCode}" size="1" required="true">
              <apex:selectOptions value="{!CurrencyValues}"/>
            </apex:selectList>
        </apex:pageBlockSectionItem> 
    </apex:pageBlockSection>
    </apex:pageBlock>
</apex:form>

Apex Class:-

public class CurrencyClass{


    public CurrencyClass (ApexPages.StandardController ctr){
    }

    public List<SelectOption> getCurrencyValues()
    {
      List<SelectOption> options = new List<SelectOption>();

       Schema.DescribeFieldResult fieldResult = Opportunity.CurrencyIsoCode.getDescribe();

       List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();

       for( Schema.PicklistEntry f : ple)
       {
          //Concatinating currency values like  ( value "USD" label "U.S. Dollar" ) 

          string finalvalue= f.getValue() + ' - ' + f.getLabel() ;

          options.add(new SelectOption(finalvalue, finalvalue));
       }       
       return options;
    }

}

Attribution
Source : Link , Question Author : Robert Sösemann , Answer Author : C0DEPirate

Leave a Comment