0

How to send field label names in the JSON request body for the custom fields instead of their API names.

{  
   "0030H00004jntjiQAA":{  
      "Sample__c":true,
      "Send_To_Email__c":true,
      "Languages__c":false,
      "Level__c":false
}
}

{  
   "0030H00004jntjiQAA":{  
      "Sample":true,
      "SendToEmail":true,
      "Languages":false,
      "Level":false
}
}

Thanks, Anil Kumar

1

1 Answer 1

1

You can translate an API name into a label using code like this (where the label is obtained from a field describe result):

Contact[] cs = ...;

SObjectType[] fields = new SObjectType[] {
        Contact.Sample__c,
        Contact.Send_To_Email__c,
        Contact.Languages__c,
        Contact.Level__c
        };

// Logic for list of objects
Map<String, Object> ms = new Map<String, Object>();
for (Contact c : cs) {
    // Logic for one object
    Map<String, Object> m = new Map<String, Object>();
    for (SObjectField f : fields) m.put(f.getDescribe().getLabel(), c.get(f));
    ms.put(c.Id, m);
}

String jsonString = JSON.serializePretty(ms);

You must log in to answer this question.

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