/* 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