-1

This is my 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;}


public WrapperCriteria()
{
    this.criteriaMaster=new Criteria_Master__c();
    this.Components=new List<SelectOption>();
    this.Components1=new List<SelectOption>();
}
}

I have a method:

@AuraEnabled

public static  WrapperCriteria getComponent(string wrapval,string id) {
    String objectName;
    Criteria_Master__c cmas = new Criteria_Master__c();
    List < WrapperCriteria > warpList = (List < WrapperCriteria > ) 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 > ();
    List < SelectOption > Components;
    List < SelectOption > Components1;
    //Criteria_Master__c cmas = new Criteria_Master__c();   //write a class
    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.getValue() == wr.ObjectApiNAme) {
                        objectName = so.getLabel();
                        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));
                    ctcMasAPINames.put(pem.id, pem.name);
                    System.debug('--------Pay element MAster MAP VAlues-----' + ctcMasAPINames);
                }
                Components = options;
                system.debug('components value ::::::'+ac.Components);
            } 
            else if (wr.ObjectApiNAme == 'CTC_Master__c') {
                for (SelectOption so: ObjNames) {
                    if (so.getValue() == wr.ObjectApiNAme) {
                        objectName = so.getLabel();
                        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()));
                        ctcMasAPINames.put(fieldResult.getName(),fieldResult.getLabel());   
                    }
                }
                Components1= options;

            }
        }
    } 
    return null;   //Instead of null I want to return components and components1 to Lightning component page
}

I have couple of questions:

1.Instead of null I want to return components and components1 value to Lightning component page [As per my understanding using one method we can return only one value].How to do that?

2.I cant write return type as List selectOption why beacuse it isnt working in lightning.But in this scenario How to do this.[I need option values because i want to display that values in aura:component. If its vf page means we can easily access like this {!components}...But in Lightning how to do this....

3.How to display components & components1 value in within Lightning select option tag?

1
  • Use wrapper class to return custom desired data.
    – Raul
    Commented Mar 27, 2017 at 7:41

2 Answers 2

1

This is because the standard SelectOption class doesn't have the @AuraEnabled annotation, you'll need to create your own SelectOption class.

You can find the whole answer here: @AuraEnabled Support for Apex Class Return Types?

0
1

For some JSON encoding decoding issue(may be), SelectOption can not be returned back to Lightning Component Controller. I have faced this issue.

Alternatively you can return the data in a String to String map. Fill up the values from your SelectOption list to a map and then return it.

To return back 2 instances at once you will need a wrapper instance. So write a wrapper class to hold 2 Maps, each for component and component1.

public class DataContainer
{
  public Map<String, String> componentMap{get;set;}
  public Map<String, String> componentMap1{get;set;}
}

and then populate the maps from your lists in your method.

DataContainer dc = new DataContainer();
dc.componentMap = new Map<String, String>();
dc.componentMap1 = new Map<String, String>();

for(SelectOption so : Components )
{
  dc.componentMap.put(so.getLabel(), so.getValue());
}

//do similarly for component1 as well.

then return the dc instance from the method.

0

Not the answer you're looking for? Browse other questions tagged .