[SalesForce] Object and Field Describe in Lightning Component

Is it possible to get sObjectDescribe in Lightning Components?
In my case I need to have all possible values of picklist-field, but filter out the list of options conditionally.

Best Answer

You can do the describe call in the apex class and filter out the value as you want and return those value to lightning controller:

Adding a snap of the apex class method and lightning controller:

Add the following in the Apex class:

public class picklistWrapper {
    @AuraEnabled
    public String strValue {get;set;}
    @AuraEnabled
    public String strLabel {get;set;}

    public picklistWrapper(String strValue, String strLabel) {
        this.strValue = strValue;
        this.strLabel = strLabel;
    }
}

@AuraEnabled
public static List<picklistWrapper> getPicklistValues() {

    List<picklistWrapper> lstPWrapper = new List<picklistWrapper>();
    Schema.DescribeFieldResult fieldResult = Account.BillingStateCode.getDescribe();

    for(Schema.PicklistEntry f : fieldResult.getPicklistValues()) {

        //write your logic to filter the values here
        lstPWrapper.add(new picklistWrapper(f.getValue(), f.getLabel()));
    }
    return lstPWrapper
}

Add the following to the lightning controller:

getInitialData : function(component, event, helper) {
    var action = component.get("c.getPicklistValues");

    action.setCallback(this, function(response){
        var state = response.getState();
        if(state === "SUCCESS") {
            var result = response.getReturnValue();
            console.log('=====result====',result);//you will get picklist values here
        }
    })
    $A.enqueueAction(action);
}