-1

This question already has an answer here:

/* Wrapper class */

public class WrapperCriteria
{   
@AuraEnabled
public Criteria_Master__c  criteriaMaster {get;set;}
@AuraEnabled
public Integer index  {get;set;}
@AuraEnabled
public Action_Criteria__c record  {get;set;}
@AuraEnabled
public string CriteriaMasId  {get;set;}
@AuraEnabled
public String ObjectApiNAme  {get;set;}
@AuraEnabled
public Criteria_Master__c CriteriaMas{get;set;}
@AuraEnabled
public String SpecialOperator {get;set;}
@AuraEnabled
public String SelObjectName {get;set;}
@AuraEnabled
public String FieldName{get;set;}
@AuraEnabled
public String Operator{get;set;}
@AuraEnabled
public decimal specialOperatorSlashValue{get;set;}
@AuraEnabled
public decimal specialOperatorValue{get; set;}
@AuraEnabled
public List<SelectOption> ComponentsInWpr{get; set;}
@AuraEnabled
public List<SelectOption> Components{get; set;}
 @AuraEnabled
public List<SelectOption> Components1{get; set;}

public WrapperCriteria()
{
    this.criteriaMaster=new Criteria_Master__c();

}

server side:

  @AuraEnabled
public static WrapperCriteria getComponent(string wrapval,string id) {
    String objectName;
    Criteria_Master__c cmas = new Criteria_Master__c();
    List < WrapperCriteria > warpList = (List < WrapperCriteria > )System.JSON.deserialize(wrapval, List<WrapperCriteria >.class);

    system.debug('::::::wrList value::::' + warpList);
    system.debug('id value ::::::' + id);

        WrapperCriteria ac=new WrapperCriteria ();
    List < SelectOption > ObjNames = new List < SelectOption > ();
    ObjNames.add(new SelectOption('', '--None--'));
    ObjNames.add(new selectoption('Pay_Element_Master__c', 'Pay Element'));
    ObjNames.add(new selectoption('CTC_Master__c', 'CTC Master'));

    Map <String,String> ctcMasAPINames = new Map < String, String > ();
    cmas = [select id, Name, Action_Criteria__c, Company_Master__c from Criteria_Master__c where Id=:id];

    if (warpList.size() > 0) {
        for (WrapperCriteria wr: warpList) {
            List <SelectOption > options = new List <SelectOption > ();
            if (wr.ObjectApiNAme == 'Pay_Element_Master__c') {
                for (SelectOption so: ObjNames) {
                    if (so.Value == wr.ObjectApiNAme) {
                        objectName = so.Label;
                        system.debug('****objectname *****' + objectName);
                    }
                }
                wr.SelObjectName = objectName;     //aassigned to wrapper


                for (Pay_Element_Master__c pem: [select id, name, Company_Master__c from Pay_Element_Master__c where Company_Master__c = : cmas.Company_Master__c]) {
                    options.add(new SelectOption(pem.id, pem.name));
                    //dc.componentMap.put(pem.id,pem.name);
                    ctcMasAPINames.put(pem.id, pem.name);
                    System.debug('--------Pay element MAster MAP VAlues-----' + ctcMasAPINames);
                }
                ac.Components = options;
                system.debug('ac.Components value:::::::'+ac.Components);
            } 
            else if (wr.ObjectApiNAme == 'CTC_Master__c') {
                for (SelectOption so: ObjNames) {
                    if (so.Value == wr.ObjectApiNAme) {
                        objectName = so.Label;
                        system.debug('-----------objectname --------------' + objectName);
                    }
                }
                wr.SelObjectName = objectName;
                Map < String, Schema.SObjectType > globalDescription = Schema.getGlobalDescribe();
                Schema.sObjectType objType = globalDescription.get('CTC_Master__c');
                Schema.DescribeSObjectResult ob = objType.getDescribe();

                if (ob == Null) {
                    AuraHandledException e = new AuraHandledException('Invalid sObject Type');
                    e.setMessage('Invalid sObject Type');
                    system.debug(e);
                    throw e;

                }
                Map < String, Schema.SObjectField > mapFieldList = ob.fields.getMap();

                for (Schema.SObjectField field: mapFieldList.values()) {
                    Schema.DescribeFieldResult fieldResult = field.getDescribe();
                    if (fieldResult.isAccessible() && (fieldResult.getType() == Schema.DisplayType.Integer || fieldResult.getType() == Schema.DisplayType.Double || fieldResult.getType() == Schema.DisplayType.Currency)) {
                        options.add(new SelectOption(fieldResult.getName(), fieldResult.getLabel()));
                        //dc.componentMap1.put(fieldResult.getName(),fieldResult.getLabel());
                        ctcMasAPINames.put(fieldResult.getName(),fieldResult.getLabel());   
                    }
                }
                ac.Components1= options;
                system.debug('ac.Components1 value:::::::'+ac.Components1);
            }
        }
    }

    return ac;
}

javascript side:

    Method2: function(component, event, helper) {

    var comp = component.get("v.wrplst");
    var compJson = JSON.stringify(comp);
    var Id1 = component.get("v.theId");
    var compAction = component.get("c.getComponent");
    compAction.setParams({
        "wrapval":compJson,
        "id": Id1,
    });
    compAction.setCallback(this, function(re) {
        var state = re.getState();
        if (state ==='SUCCESS') {
           var da=re.getReturnValue();
           var myJSON = re.getReturnValue();
           // var myObj = JSON.parse(myJSON);
            alert('myJson value:::::'+myJSON);
            //alert('::::::::::::::::'+( myObj.components);

           }
        else if(state==='error'){
            alert('error value');
        }
            else if(state==='INCOMPLETE'){
                alert('incomplete values:::');

            }
    });
    $A.enqueueAction(compAction);
}

Problem : Javascript side shows null values.If I use string as return type for wrapper..It will work...why this code isnt working??...I have tried parameter like this List wraplist as a parmeter...but it doesn't work for me

marked as duplicate by Eric, Martin Lezer, Dave Humm, Ratan Paul, Raul Apr 3 '17 at 11:35

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    It's a known issue that unless you set default values they will not be accessible in your component. Supposed to be fixed in summer 17 – Eric Apr 3 '17 at 8:53
0

I can see 2 things:

  • Your WrapperCriteria class has a Components attribute, whereas your JS Controller is using myObj.components (lower case). Be careful as JavaScript is case sensitive
  • This same Components attribute is a list of SelectOption which is not @AuraEnabled. You'll need to create your own SelectOption class as described here: @AuraEnabled Support for Apex Class Return Types?
0

Change your wrapper class :

public class WrapperCriteria
{   
@AuraEnabled
public Criteria_Master__c  criteriaMaster ;
@AuraEnabled
public Integer index  ;
@AuraEnabled
public Action_Criteria__c record  ;
@AuraEnabled
public string CriteriaMasId  ;
@AuraEnabled
public String ObjectApiNAme  ;
@AuraEnabled
public Criteria_Master__c CriteriaMas;
@AuraEnabled
public String SpecialOperator ;
@AuraEnabled
public String SelObjectName ;
@AuraEnabled
public String FieldName;
@AuraEnabled
public String Operator;
@AuraEnabled
public decimal specialOperatorSlashValue;
@AuraEnabled
public decimal specialOperatorValue;
@AuraEnabled
public List<SelectOption> ComponentsInWpr;
@AuraEnabled
public List<SelectOption> Components;

@AuraEnabled public List Components1;

public WrapperCriteria() { this.criteriaMaster=new Criteria_Master__c(); }

  • I didnt get ..Piyush Kumar – SFDC FAN Mar 31 '17 at 11:28

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