0

The new force:recordData component is awesome since it allows us to retrieve sObjects without a direct apex server call. However as a managed package provider, we have a very common situation where we need to conditionally include the CurrencyIsoCode field if the organization is using multiple currencies. It looks like including this in the fields attribute causes an internal server error when the org is single currency. It would have been great if this was supported but I am not surprised that it isn't. This leads me to two questions:

  1. Is there any way to determine if an org is multi-currency without hitting the server? It doesn't look like this info exists in any of the global value providers.
  2. If we need to hit the server to determine what fields to query, is there actually any advantage to using the force:recordData component? It seems as though this may result in two server calls a lot of the time.
0

Try this in your component (.cmp):

<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<aura:attribute name="record" type="Object" />
<aura:attribute name="requiredFields" type="String[]" />


<aura:if isTrue="{!greaterthan(v.requiredFields.length,0)}">
    <force:recordData recordId="{!v.recordId}" fields="{!v.requiredFields}" mode="VIEW" targetFields="{!v.record}"/>   
</aura:if>

And in controller (.js):

({
    doInit: function(component, event, helper) {
        var myAction = component.get("c.init");

        myAction.setCallback(this, function(response) {
            if (response.getState() === "SUCCESS") {
                component.set("v.requiredFields", response.getReturnValue());
            }
        });

        $A.enqueueAction(myAction);
    },
})

And in APEX controller (.cls) you just return (String[]) appropriate API field names.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.