1

Below is the way I store the keys and values in my map.

Map<String, Object> mapNew = new Map<String, Object>();
Object obj = record.get(fieldName) != null ? record.get(fieldName) : null;    
mapNew.put(fieldMap.get(fieldName).getDescribe().getLabel(), obj); // contains field label and corresponding field value

Response in system.debug is

recordDetail={Account Name=Test, Active=true, Business Phone=null, [email protected], Title=Mr.}

But when I am printing the same map on the javascript side, response looks like this,

Account Name: "Test"
Active: true
Email: "[email protected]"
Title: "Mr."

I want to know why the key with an empty value entry gets omitted automatically and how to handle this issue in javascript side.

1 Answer 1

0

I don't know the specifics as to why key's with null values in maps are omitted when passing data to the client, but, a simple enough operation would be to convert your map to a string. Then, from the client, when receiving the server payload, simply use JSON.parse(variable) in order to convert back to an object.

1
  • The above trick worked. Thanks @glls
    – sfdcOwl
    May 10, 2022 at 5:30

You must log in to answer this question.

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