I'm trying to get the Metadata of Global picklist from tooling API Below is the code
Map<id, MetadataRecords> metadataMap = new Map<id, MetadataRecords>();
String GLOBALVALUESETNAME = 'GPICKLIST'; //name of the global valueset you want to retrieve
HttpRequest req = new HttpRequest();
req.setHeader('Authorization', 'Bearer ' + System.userInfo.getSessionID());
req.setHeader('Content-Type', 'application/json');
req.setEndpoint(URL.getSalesforceBaseUrl().toExternalForm()+'/services/data/v50.0/tooling/query/?q=Select+FullName,Metadata,Id+FROM+GlobalValueSet+WHERE+DeveloperName=\''+GLOBALVALUESETNAME+'\'');
req.setMethod('GET');
Http request = new Http();
HttpResponse res = request.send(req);
system.debug(res.getBody());
Below is the response received from the above API
Response:
{
"size": 1,
"totalSize": 1,
"done": true,
"queryLocator": null,
"entityTypeName": "GlobalValueSet",
"records": [
{
"attributes": {
"type": "GlobalValueSet",
"url": "/services/data/v50.0/tooling/sobjects/GlobalValueSet/0Nt3N0000007Phetvd"
},
"Metadata": {
"customValue": [
{
"color": null,
"default": false,
"description": null,
"isActive": null,
"label": "QWER",
"urls": null,
"valueName": "QWER"
}
],
"description": null,
"masterLabel": "GPICKLIST",
"sorted": false,
"urls": null
},
"Id": "0Nt3N0000007Phetvd"
}
]
}
Trying to Remove the Id from the above response, Reason is when i tried to do Post action (Add new Value in the Picklist) its threw the error saying that id cannot be sent of the JSON payload.
Can you help me how to remove the ID key from the Request.
Wrapper Class
public class RootObjectMetadata{
public List<MetadataRecords> records{ get; set; }
}
public class MetadataRecords {
public id Id { get; set; }
public string FullName { get; set; }
Metadata metadata{ get; set; }
}
public class Metadata {
public List<CustomValue> customValue { get; set; }
public Object description { get; set; }
public String masterLabel{ get; set; }
public Boolean sorted { get; set; }
}
public class CustomValue {
public Object color { get; set; }
//public Boolean default;
public Object description { get; set; }
public boolean isActive { get; set; }
public String label { get; set; }
public String valueName { get; set; }
}