0

I am not getting how to write the return statement. I want to return both schemaMap and fieldMap. Here is my code.

public class ObjectAll {

@AuraEnabled
public static List<String> getObjectAPI() {
    List<String> objectAPI = new List<String>();
    return objectAPI;
}

@AuraEnabled
public static Map<String,String> getFieldNames() {
    String query = '';
    Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
    Map<String, Schema.SObjectField> fieldMap = schemaMap.get('Account').getDescribe().fields.getMap();

    for(String fieldName : fieldMap.keyset()){
        query = fieldName + ',' + query;
    }

    System.debug('---------------->> a ' + query);

    return ;
}

}
  • 2
    Serialize each of them into JSON and add it in list of String. And then simply return that list – Rohit Mourya Sep 26 '17 at 8:52
6

You just need to declare another class as a wrapper. Then, you just return a new instance of this class.

Here's the right code:

public class ObjectAll {
    //The wrapper class
    public class Wrapper{
        @AuraEnabled
        public Map<String, Schema.SObjectType> SchemaMap {get; set;}

        @AuraEnabled
        public Map<String, Schema.SObjectField> FieldMap {get; set;}
    }

    @AuraEnabled
    public static List<String> getObjectAPI() {
        List<String> objectAPI = new List<String>();
        return objectAPI;
    }

    @AuraEnabled
    public static Wrapper getFieldNames() {
        Wrapper wrapper = new Wrapper();

        String query = '';
        wrapper.SchemaMap = Schema.getGlobalDescribe();
        wrapper.FieldMap = schemaMap.get('Account').getDescribe().fields.getMap();

        for(String fieldName : wrapper.FieldMap.keyset()){
            query = fieldName + ',' + query;
        }

        System.debug('---------------->> a ' + query);

        return wrapper;
    }

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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