I am doing a rest call with the below endpoint
string endPoint = 'https://test.salesforce.com/services/data/v43.0/query?q=SELECT+Name+,+RecordTypeId+,+Code__c+from+Account';
I have the below class to map the above response
public class WrapperClass {
public List<resultWrapper> records {get;set;}
public class resultWrapper{
public string Name {get;set;}
public string RecordTypeId {get;set;}
public string Code__c {get;set;} //// Here i am getting the error "Invalid character in identifier"
}
}
Http h1=new Http();
HttpRequest req1=new HttpRequest();
req1.setHeader('Authorization','Bearer '+wResp.access_token);
req1.setHeader('Content-Type','application/json');
req1.setMethod('GET');
req1.setEndpoint(endPoint);
HttpResponse hresp1=h1.send(req1);
WrapperClass wResp1=(WrapperClass) JSON.deserialize(hresp1.getBody(),WrapperClass.class);
JSON
{
"totalSize": 2073227,
"done": false,
"nextRecordsUrl": "/services/data/v43.0/query/XXXXXXXXXXXXXXXX-2000",
"records": [{
"attributes": {
"type": "Account",
"url": "/services/data/v43.0/sobjects/Account/0012500000j2rfNAAQ"
},
"Name": "Test ytymnjkhkjhhuty0",
"RecordTypeId": "012D0000000QoolIAC",
"Code__c": "1234567890"
}]
}
How to resolve this error. How to map Custom field to Json Variables.
Code__c
to Code and try.resultWrapper
? Your records are just sObjects, so you can deserialize aList<My_Sobject__c>
.