You need to sign in to do that
Don't have an account?
ForceRookie
How to get all fields dynamically based on Object selected?
Help me. What's wrong with the code? I'm trying to get All the Fields of Object.
@AuraEnabled public static List<SelectOption> getAllObjectFields(String objectName) { List<SelectOption> fieldList = new List<SelectOption>(); Map <String, Schema.SObjectField> fieldMap = Schema.getGlobalDescribe().get(objectName).getDescribe().fields.getMap(); for(Schema.SObjectField sfield : fieldMap.values()) { if (sfield.getDescribe().isAccessible()) { fieldList .add(new SelectOption(sfield.getDescribe().getName(),sfield.getDescribe().getLabel())); } } return fieldList ; }
Use this js code
All Answers
Are you using a namespace ? If so, you will need the namespace in teh objectname e.g. MyDomain__Account
Use this js code
Try the below code it works for me and it may be helpful for you: I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi