5

In Apex we can do

Hiearchy_Custom_Setting__c.getInstance().Field__c

In Visualforce we can do

$Setup.Hiearchy_Custom_Setting__c.Field__c

Is there any equivalent way to access easily from a Lightning component's helper.js?

I tried the following, which I'd think would work, but is returning "undefined" when it's definitely true:

Controller:

    public Boolean isBigDataMode {
      get {
          if (isBigDataMode == null) {
              isBigDataMode = Product_Pricing_Settings__c.getInstance().Use_Big_Data_Mode__c == true;
          }
          return isBigDataMode;
      }
      set;
    }

Component:

    <aura:attribute name="isBigDataMode" type="Boolean" default="{!isBigDataMode}"/>

Helper:

({
    getBigDataMode : function(component){
      console.log("big data: "+component.get("v.isBigDataMode"));
      return component.get("v.isBigDataMode");
    }
})

This is returning to the console

big data: undefined

4

I would recommend the same as prashanthkr, this code should work:

JS Controller:

    var action = component.get("c.getHiearchySettings");

    action.setCallback(this, function(response){
        if(component.isValid() && response !== null && response.getState() == 'SUCCESS'){
            //saving custom setting to attribute
            component.set("v.settings", response);
            console.debug(response.Use_Big_Data_Mode__c );//Check the output
            //... rest of your code
        }
    });

    $A.enqueueAction(action);

Apex Controller:

public class MyController{
    @AuraEnabled
    public static MyHiearchy__c getHiearchySettings(){
        return MyHiearchy__c.getInstance();
    }
}
  • 1
    Not sure if the API changed, but I think it's supposed to be response.getReturnValue().Use_Big_Data_Mode__c – JDB still remembers Monica May 14 '18 at 19:56
  • 1
    Instead of component.set("v.settings", response); I would recommend component.set("v.settings", response.getReturnValue(); – Mike Paisner Dec 31 '18 at 23:22
2

You would have to create an @AuraEnabled action method that returns the value of isBigDataMode to the component. You can find more details here

  • 1
    Tried that, wasn't able to get it working. Have a code snippet sample? – Ray Dehler Jul 20 '16 at 1:59

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.