I have list of accounts and want to use them for post request. How can I remove unnecessary fields like id to set that list in setbody? Now I am just using for loop and json serialize.

Some code. So I need remove id and some other fields. Maybe use Map with key?

Http http = new http();
HttpRequest request = new httprequest();
for(Account acc: accList){
String body = json.serialize(acc);


Upd: AccList is just a list of recently created account records.It’s in trigger so Trigger.new.

  • 3
    What have you tried? Where are you stuck?
    – David Reed
    Aug 17, 2021 at 16:28
  • @DavidReed tried what wrote. And parser, but I don’t get how to remove exact field. So I have only list and for loop for it.
    – Serami
    Aug 17, 2021 at 17:29
  • Where are you getting accList from? Your code sample is incomplete.
    – Adrian Larson
    Aug 17, 2021 at 18:12
  • @AdrianLarson it’s just recently created account records . Trigger.new.
    – Serami
    Aug 17, 2021 at 18:19

1 Answer 1


Probably the easiest way to do what you want is use getPopulatedFieldsAsMap, then remove any fields you want to block.

Map<String, Object> fields = acc.getPopulatedFieldsAsMap();
// etc
  • Looks good, but I don’t really want convert to map. But couldn’t fount better way. Thanks.
    – Serami
    Aug 17, 2021 at 18:37

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