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
Rst123Rst123 

Display only USD value AUD 450,000.00 (USD 455,843.92) to 455,843.92

i have created a visualforce page diplaying set of fields data in columns :-

My Column  :-

 

<apex:column headerValue="Total Price(USD)">                           

  <apex:repeat value="{!varOpp.opp.OpportunityLineItems}" var="PrdLst" rendered="{!if(varOpp.opp.OpportunityLineItems.size>0 , true, false)}" >                                   

<apex:outputField value="{!PrdLst.TotalPrice}"/><br/>                                  

<apex:param value="{!convertCurrencyWithApexCode}"/>                             

</apex:repeat>                                              

</apex:column>

 

Now, I'm getting the data in AUD 450,000.00 (USD 455,843.92) format where i want to display only USD 455,843.92

crop1645crop1645

RST1

 

apex:outputField will display the value as it would be displayed on the normal Force.com UI; thus, if the Oppo has currencyIsoCode = AUD and your corporate currency is USD, you get what you observed.

 

If you only want the corporate currency value and you are not using dated exchange rates, then this post will be the answer - http://boards.developerforce.com/t5/Apex-Code-Development/How-to-get-currency-value-in-corporate-currency/td-p/256833

 

If you are using date exchange rates, you'll need something like this (presumed included in a Utility class):

    //  ----------------------------------------
    //  convertToOrgCurrency
    //  ----------------------------------------
    private static Map<ID,DatedConversionRate>              dcrIdToDcrMap;                      // Singleton, remember when first referenced, key = DatedConversionRate.id

    public static Decimal convertToOrgCurrency(String currencyIso, Decimal currencyVal, Date currencyDate) {
        Decimal res;
        if (currencyIso == null || currencyVal == null) {}
        else {
            if (dcrIdToDcrMap == null)              // build the map only once for life of the trsnaction
                dcrIdToDcrMap = new Map<ID,DatedConversionRate> ([select id, isoCode, conversionrate, nextStartDate, startDate from DatedConversionRate]);
            for (DatedConversionRate dcr: dcrIdToDcrMap.values()) {
                if (dcr.isoCode != currencyIso)                                         continue;   // look for a match in table against input currency
                if (currencyDate < dcr.startDate || currencyDate >= dcr.nextStartDate)  continue;   // not in the range of effective dates
                System.debug(LoggingLevel.INFO,'Converting using dcr: ' + dcr);
                res =  currencyVal / dcr.conversionRate;
                break;  
            }
        }
        System.debug(LoggingLevel.INFO,'convertToOrgCurrency res= ' + res);
        return res;
    }
    
    @isTest(SeeAllData=true)
    private static void testConvertToOrgCurrency() {
        System.assertNotEquals(1000.00, convertToOrgCurrency('JPY',1000.00,Date.today()));          // test presumes org currency is not JPY
        System.assertEquals(null,convertToOrgCurrency('JPY',null,Date.today()));
    }

 

 

 

As a side note, if you are using (or plan to use) dated exchange rates, you are even more hampered with apex:outputField

 

A merge field that references the Salesforce field that is associated with this output field. For example, if you want to display an output field for an account's name field, use value="{!account.name}". You cannot associate this output field with a currency merge field if that field value is calculated using dated exchange rates.

 In this case, you'll need a reusable VF component to display your corporate currency like this:

 

<apex:component >
	<!--  Display a currency field as xxx n,nnn,nnn.nn where xxx is ISO currency -->
	<!--  Works around VF limitation on using dated exchange rates and Opportunity, OLI currency fields -->
	
	<apex:attribute name="value" 		description="Reference to the merge field of type currency" type="Decimal" 	required="true"  />
	<apex:attribute name="currency" 	description="Reference to the merge field currencyISO" 		type="String" 	required="true"  />
	
	<apex:outputText value="{!currency} {0,number,##,###,##0.00}">
		<apex:param value="{!value}"/>
	</apex:outputText>
</apex:component>