-2

I have a class

public static List<AccFieldWrapper> AcctFields(String Account){
       
        Map <String,Schema.SObjectType> mapobject = Schema.getGlobalDescribe();
        Schema.SObjectType sobjType = mapobject.get('Account');
        Schema.DescribeSObjectResult result1 = sobjType.getDescribe();
        Map<String, Schema.SObjectField> MapofField = result1.fields.getMap();
        System.debug(MapofField);
        
        List<AccFieldWrapper>accWrapper = new List<AccFieldWrapper>();
        
        for(String fieldName : MapofField.keySet()) {
            Schema.SObjectField field = MapofField.get(fieldName);
            AccFieldWrapper obj = new AccFieldWrapper();
            obj.ApiName = fieldName;
            obj.Label = MapofField.get(fieldName).getDescribe().getLabel();
            System.debug(obj.Label);
            accWrapper.add(obj);
        }
       
        return accWrapper;
    }

    public class AccFieldWrapper{
       public string ApiName;
       public string Label;
    }
}
0

You need to get fields of the account a filter them by isExternalId like so.

for (SObjectField sObjectField : Schema.getGlobalDescribe().get('Account').getDescribe().fields.getMap().values()) {
    if (sObjectField.getDescribe().isExternalId()) {
        System.debug(sObjectField.getDescribe().getLabel());
    }
}
3
  • Thanks a lot :)
    – Teshu
    Aug 19 at 14:41
  • Could you also please help me with this
    – Teshu
    Aug 19 at 14:42
  • How to dynamically pass the parameters for upsert operation mainly external id needs to be dynamic?
    – Teshu
    Aug 19 at 14:43

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.