0

I need to get a map of API name and record value Map

ServiceContract objServiceContract = [SELECT Id, PriceBook2Id,Name From ServiceContract  LIMIT 1];

List<Schema.FieldSetMember> fieldList=SObjectType.ServiceContract.FieldSets.fieldsetName.getFields();
            for(Schema.FieldSetMember f : fieldList) {
                valuemap.put(f.getFieldPath() , f.Label);
            }

I am getting map of field label and api name from field set.

0

Its quite simple using getPopulatedSobjectField() method from Sobject.

ServiceContract objServiceContract = [SELECT Id, PriceBook2Id,Name From ServiceContract  LIMIT 1];


Map<String, Object> fieldsAPINameToValue = objServiceContract .getPopulatedFieldsAsMap();
1
  • getPopulatedFieldsAsMap() only return fields with value , if field value is blank it will return nothing. – Edward Jul 23 '19 at 21:06

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.