You need to sign in to do that
Don't have an account?
Shatrughna Salunke
How to add new field in request body using apex class
Hello,
How to add new field in belwo request body using apex class i've string of requestbody.
Fiedld Name=ERP_Set_Status__c and Customer_status__C
String requestbody='
{
"platform": {
"record": {
"query_type": {
"content": "11"
},
"consumer_title": "Mr.",
"consumer_first_name": "Shatrughna",
"consumer_surname": "Salunke",
"consumer_date_of_birth": "1971-10-08",
"address_line1": "19",
"address_line2": "",
"address_line3": "",
"town": "Pune Hinjawadi",
"postcode_2099407766": ""
}
}
}';
How to add new field in belwo request body using apex class i've string of requestbody.
Fiedld Name=ERP_Set_Status__c and Customer_status__C
String requestbody='
{
"platform": {
"record": {
"query_type": {
"content": "11"
},
"consumer_title": "Mr.",
"consumer_first_name": "Shatrughna",
"consumer_surname": "Salunke",
"consumer_date_of_birth": "1971-10-08",
"address_line1": "19",
"address_line2": "",
"address_line3": "",
"town": "Pune Hinjawadi",
"postcode_2099407766": ""
}
}
}';
Use the below code it may helpful for you.
public class RequestBodyApex{
public class WrapperClass {
public Platform platform;
}
public class Platform {
public Record record;
}
public class Record {
public Query_type query_type;
public String consumer_title;
public String consumer_first_name;
public String consumer_surname;
public String consumer_date_of_birth;
public String address_line1;
public String address_line2;
public String address_line3;
public String town;
public String postcode_2099407766;
public String ERP_Set_Status;
public String Customer_status;
}
public class Query_type {
public String content;
}
public static void requestBodyMethod(){
String requestbody = '{"platform": {"record": {"query_type": { "content": "11"},"consumer_title": "Mr.","consumer_first_name": "Shatrughna","consumer_surname": "Salunke","consumer_date_of_birth": "1971-10-08","address_line1": "19","address_line2": "","address_line3": "","town": "Pune Hinjawadi","postcode_2099407766": ""}}}';
WrapperClass requestbodyObj = (WrapperClass) JSON.deserialize(requestbody, WrapperClass.class);
if(requestbodyObj.platform != null && requestbodyObj.platform.record != null){
requestbodyObj.platform.record.ERP_Set_Status = 'XXXXXXXXX';
requestbodyObj.platform.record.Customer_status = 'AAAAAAAAAA';
requestbody = Json.serialize(requestbodyObj);
}
}
}
I hope you find the above solution helpful. If it does, please mark it as Best Answer to help others too.
Thanks and Regards,
Sachin Arora
www.sachinsf.com