You need to sign in to do that
Don't have an account?
sksfdc221
Create record from JSON response recieved from external system
I have a json response which I got from external system using its endpoint. Now I need to create account records in Salesforce using that response.
Below is my Rest Callout code:
Below is my JSON response:
Now, using JSON2APEX, I have created this below JsonParser class
Here, licenseCode is the unique field and now, I'm stuck at the point where I need to create Account records in my org using the Json response above. Can anyone please suggest on how to do so. Thanks!
Below is my Rest Callout code:
String jsonbody = '{ ' + '"accountName": "Test"' + '}' ; HttpRequest req = new HttpRequest(); req.setMethod('GET'); req.setTimeout(120000); req.setHeader('content-type', 'application/json'); req.setHeader('Content-Length', String.valueOf(jsonBody.length())); req.setEndpoint('<endpoint>'); System.debug('Input Request:' + jsonBody); req.setBody(jsonBody); Http http = new Http(); HTTPResponse res = http.send(req); System.debug(res.toString()); System.debug('STATUS:' + res.getStatus()); System.debug('STATUS_CODE:' + res.getStatusCode()); String response = res.getBody(); system.debug('Output==>'+ response);
Below is my JSON response:
{ "code": 200, "value": { "data": [ { "accountName": "Test Account", "address": "Test Address" "licenseCode": "01" } ], "message": "Account Details retrieved successfully." } }
Now, using JSON2APEX, I have created this below JsonParser class
public class JsonParser{ public value value{get;set;} public Integer code{get;set;} public class value{ public String message{get;set;} public Integer code{get;set;} public list<data> data{get;set;} } public class data{ public String accountName{get;set;} public String address{get;set;} public String licenseCode{get;set;} } public static JsonParser parse(String json){ return (JsonParser) System.JSON.deserialize(json, JsonParser.class); } }
Here, licenseCode is the unique field and now, I'm stuck at the point where I need to create Account records in my org using the Json response above. Can anyone please suggest on how to do so. Thanks!
https://salesforce.stackexchange.com/questions/179744/create-salesforce-records-from-json-response
https://www.biswajeetsamal.com/blog/dynamic-data-creation-in-salesforce-from-json-data-without-using-wrapper-class/
Let me know if this helps, if it does, please close the query by marking it as solved. It may help others in the community. Thank You!