• Chengdu sanji
  • NEWBIE
  • 5 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

Hi everyone, I'm new to lightning and trying to learn few things.
Problem is that I am able to display the picklist for objects as well as a multi select picklist. But when I click on an object I am getting the related fields in my console.log(resoponseValue) but not in the UI of my aura app when I run the code. Please help me acheiving this task. Here is my code for the same :

Apex Controller:
public class PickList {
    @AuraEnabled
    public static List <String> getPiklistValues(String objName) {
        System.debug('objName--'+objName);
        List<String>apiNames =  new list<String>();
        
        Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
        Map<String, Schema.SObjectField> fieldMap=new  Map<String, Schema.SObjectField>();
        if(objName.contains('Account')){
            fieldMap= schemaMap.get('Account').getDescribe().fields.getMap();             
        }else if(objName.contains('Case')){
            fieldMap= schemaMap.get('Case').getDescribe().fields.getMap();   
        }else if(objName.contains('Contact')){
            fieldMap= schemaMap.get('Contact').getDescribe().fields.getMap();   
        }else if(objName.contains('Opportunity')){
            fieldMap= schemaMap.get('Opportunity').getDescribe().fields.getMap();   
        }
        
        for(String fieldName : fieldMap.keyset() )
        {
            system.debug('@@@@@@@'+fieldName); 
            apiNames.add(fieldName);
        }
        return apiNames;
    }
}

Cmp : 
<aura:component controller="PickList" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction,lightning:actionOverride" access="global" >
    <aura:attribute name="options" type="List" default="Select Object, Account, Case, Contact, Opportunity"/>
    <aura:attribute name="selectedValue" type="String" />
    <aura:attribute name="FieldsList" type="List" />
    <aura:attribute name="SelectedFieldsList" type="List" />
   <!-- <aura:handler name="init" action="{!c.doInit}" value="{!this}"/>-->

    <!--Code for displaying objects in picklist-->
    <select style="border: 1px solid #A9A29E;" class="slds-select"  id="objectName" onchange="{!c.myAction}">
        <aura:iteration items="{!v.options}" var="abc">
            <option value="{!abc}" text="{!abc}" />
        </aura:iteration>
    </select>
    <!--Code for displaying fields of object-->
    <div class="slds-m-around_xx-large">
        <lightning:dualListbox aura:id="selectFields"
                               name="Fields"
                               label="Select Fields"
                               sourceLabel="Available Fields"
                               selectedLabel="Selected Fields"
                               options="{!v.FieldsList }"
                               value="{!v.SelectedFieldsList}"
                               onchange="{!c.handleSubmitChange}"/>
        <lightning:button variant="brand" label="Submit" onclick="{!c.getSelectedFields}" />
    </div>
</aura:component/>

Controller JS :
({
 myAction : function(component, event, helper) {
        var action = component.get('c.getPiklistValues');
        var t=document.getElementById("objectName").value;
        alert('object--'+t);
        action.setParams({
            objName : t,
        });
        action.setCallback(this,function(response){
            var responseValue = response.getReturnValue();
                    console.log(responseValue);
            component.set("v.FieldsList",responseValue);
        });
        $A.enqueueAction(action);
    },
    handleSubmitChange: function (component, event, helper) {
        //alert('ok');
        var e = event.getParam("value");
        component.set("v.SelectedFieldsList", e);
    },
    getSelectedFields : function(component, event, helper){
        // alert('fine');
        var s = component.get("v.SelectedFieldsList");
        console.log('$$$$' , s);
    }
})

Thanks in advance.