I have a custom setting with API Name: Company_Setting__c. I need to access the value stored in this custom setting in lightning component. I got a field with API Name: Company_Phone__c.
Below is my code:
Apex Controller:
@AuraEnabled
public static Company_Setting__c getCompanySetting(){
return Company_Setting__c.getInstance();
}
Ligntning Component:
<aura:attribute name="companySetting" type="Map" default="{}" />
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
Lightning Component Controller:
doInit: function(component, event, helper) {
var getSettingsAction = component.get("c.getCompanySetting");
getSettingsAction.setCallback(this, function(response) {
if (component.isValid() && response !== null && response.getState() == 'SUCCESS') {
component.set("v.companySetting", response.getReturnValue());
console.log("Company Setting loaded.");
} else {
console.log("Failed to load Company Setting.");
}
});
$A.enqueueAction(getSettingsAction);
}
However, when use a button to alert with value alert(component.get("v.companySetting.Company_Phone__c"));
it just show as undefined.