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
ShikibuShikibu 

Visualforce unable to display any currency field if advanced currency management enabled?

I have a vf page that was working ok, but failed as soon as I enabled advanced currency management.

 

Here's the relevant markup:

 

 

<apex:column headerValue="Amount"><apex:outputfield value="{!opp.Amount}"/></apex:column>

 

 and here's the error (which was followed by a stack trace):

 

 

Currency fields on entities with effective dated currency are not supported. ...Exception type: class common.exception.ApiException Exception msg: Currency fields on entities with effective dated currency are not supported. Stack trace: common.exception.ApiException: Currency fields on entities with effective dated currency are not supported. at core.apexpages.components.ApexFieldComponentBase.compile(ApexFieldComponentBase.java:903) ...

 

 I filed a support case with Salesforce, and our account exec wrote:

 

I have had a development team member review the error message and it seems that thiis as expecetd. 

This case has been registered to the current feature request for development in a future release. 

 

Can it be true that enabling advanced currency management makes it impossible to display any currency field in visual force?

 

 

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
ShikibuShikibu

I think I have figured out a workaround. Use a custom component controller, and copy the dated exchange rate currency from Opportunity to a custom object (for which dated exchange rates are not supported).

 

Markup: 

 

 

<c:currency value="{!opp.Amount}" currencyIsoCode="{!opp.CurrencyIsoCode}"/>

 

Component: 

 

 

<apex:component controller="currencyComponentController"> <apex:attribute name="value" description="amount to display" type="Decimal" required="true" assignTo="{!value}"/> <apex:attribute name="currencyIsoCode" description="currencyIsoCode of amount" type="String" required="false" assignTo="{!currencyIsoCode}"/> <!-- Custom Component Definition --> <apex:outputfield value="{!hacked.Value__c}"/> </apex:component>

 

 

 

 

Component controller: 


public class currencyComponentController { public Decimal value {get; set;} public String currencyIsoCode {get; set;} public Hardware__c hacked { get { Hardware__c hack = new Hardware__c(); if (currencyIsoCode != null) { hack.CurrencyIsoCode = currencyIsoCode; } hack.Value__c = value; return hack; } } }

 


 

 

 

 

Message Edited by Shikibu on 07-10-2009 02:33 AM

All Answers

TehNrdTehNrd

Is the opp you are working with a new opp created in memory or an opp that you queried?

 

If queried, try also querying a field called something like CurrencyISOCode. Honestly, not sure if this will work.

TehNrdTehNrd

Actually, not looking so good....

 

You cannot associate this output feld with a currency merge feld if that
feld value is calculated using dated exchange rates.

 

Taken straight from the VF docs.

 

Message Edited by TehNrd on 07-08-2009 11:52 AM
ShikibuShikibu

I think I have figured out a workaround. Use a custom component controller, and copy the dated exchange rate currency from Opportunity to a custom object (for which dated exchange rates are not supported).

 

Markup: 

 

 

<c:currency value="{!opp.Amount}" currencyIsoCode="{!opp.CurrencyIsoCode}"/>

 

Component: 

 

 

<apex:component controller="currencyComponentController"> <apex:attribute name="value" description="amount to display" type="Decimal" required="true" assignTo="{!value}"/> <apex:attribute name="currencyIsoCode" description="currencyIsoCode of amount" type="String" required="false" assignTo="{!currencyIsoCode}"/> <!-- Custom Component Definition --> <apex:outputfield value="{!hacked.Value__c}"/> </apex:component>

 

 

 

 

Component controller: 


public class currencyComponentController { public Decimal value {get; set;} public String currencyIsoCode {get; set;} public Hardware__c hacked { get { Hardware__c hack = new Hardware__c(); if (currencyIsoCode != null) { hack.CurrencyIsoCode = currencyIsoCode; } hack.Value__c = value; return hack; } } }

 


 

 

 

 

Message Edited by Shikibu on 07-10-2009 02:33 AM
This was selected as the best answer
CorbezierCorbezier

Hi Shikibu,

 

We've come across this same issue and I am trying to implement the code that you have posted. Could you explain the line in your component controller:

 

public Hardware__c hacked 

 

 My understanding is that the __c notation refers to a custom field but this seems to me like it is a custom class? What is its purpose etc. I see that a new object of type Hardware__c is being created but I'm not exactly sure what this is. (in the context of this opportunity) Sorry if this is a very simple question!

 

Thanks in advance.

 

Ben

Message Edited by Corbezier on 07-22-2009 09:41 AM
ShikibuShikibu

Yes, Ben, you will need to use a custom object that contains a currency field. In my case, our org already had several such objects, and I chose to use the one named Hardware__c.

 

If your org has any custom object that contains a currency field, you can make use of it. If you don't have such an object, you'll need to create one (or add a currency field to an existing custom object).

 

 

CorbezierCorbezier

OK cool, so it's literally just to hold that currency value so that you can return it in the class,

 

Thanks for the quick response!

 

YarivOYarivO

Hi Shikibu,

 

I have this exact problem. I understand that you found a way to overcome this limitation.

Is there any chance of getting a step-by-step "guide" of how to apply your workaround? I read through it a few times but I couldn't figure out what goes where (I'm sure it's because of my lack of knowledge)?

PS - if anyone else in this thread can help that would be greatly appreciated of course

 

Thank you,

Yariv 

ShikibuShikibu

The idea is that you create a record, in-memory only (don't insert to database) whose purpose is only to hold the currency. This record must be a custom object (which does not support dated currencies). Call it the holding record.

 

Copy the dated currency from the standard salesforce record to the holding record. Now it is not dated, so you can display it in visualforce.

 

Good luck! 

YarivOYarivO

Thank you very much for getting back to me.

Is there any chance I could connect with you offline? I would really like to implement this but don't know how. Where do I put the different pieces of code?

Alternatively, if you could send me a detailed procedure of how to accomplish this I would be grateful.

 

Thanks! 

YarivOYarivO

Just as an FYI, I used the following workaround for resolving this: create a custom formula field which takes every one of the currency fields that need to be displayed in a Visualforce page and converts them to a number. For example: if there's a field called "Total Amount" (Total_Amount_c) create a second field of type formula (number) called "Total Amount - Numeric" (Total_Amount_Numeric_c) and the formula is: "Total Amount - Numeric" = VALUE (TEXT (Total_Amount_c)).

Then display the numeric fields on the Visualforce pages bypassing SF's weired limitation of not supporting dated currency fields in Visualforce.

CTU007CTU007
I used to create number field like what you did, but I think the component is much simpler and I dont need to create so many number fields.
HarpreetHarpreet

Hi all!

 

I just came know about this issue.

After some investigation on it, it appears that only the fields <apex:inputField> and <apex:outputField> do not work when ACM is enabled. There are other easy ways to get the currency displayed. They include:

 

1. Use the text() method to convert any currency type, percent, number, date,or  date/time field to text. 

 

The syntax:

 {!text(Opportunity.Amount)}

 

 

A working example:

 <apex:page standardController="Opportunity">

The Opportunity is worth:  {!text(Opportunity.Amount)}
</apex:page>

 

 

Another workaround is to use <apex:outputField> and passing currency amount as a parameter.

 

A working example:

<apex:page standardController="Opportunity">
The Opportunity is worth: <apex:outputText value="{0, number, 000,000.00}">

<apex:param value="{!Opportunity.Amount}" />

</apex:outputText>
</apex:page>

 

Let me know if this does not work, and I will be glad to assist.