
Thankspooja Biswas@RestResource(urlMapping='/BulkInsertaccountcontact/*')
global class Bulkinsert_accountcontact
{
global class RequestBody
{
List<Account> adList;
List<Contact> cList;
}
global class myWrapper
{
List<Account> aList;
List<Contact> cList;
public string status;
public string message;
}
@HttpPost
global static myWrapper doPost(RequestBody rb)
{
RestRequest req=RestContext.request;
RestResponse res=RestContext.response;
myWrapper response=new myWrapper(); //this is object of wrapper class
List<Account> myAList=new List<Account>();
try
{
for(Account acn:rb.adList)
{
myAList.add(acn);
}
Insert myAList;
response.aList=myAList;
for(Contact con:rb.cList)
{
//
}
//we need to insert contact List also
Insert rb.cList;
response.cList=rb.cList;
response.status='Success';
response.message='Created Successfully';
}
catch(exception ex)
{
response.aList=null;
response.cList=null;
response.status='ERROR';
response.Message='could not create record'+ ex.getMessage();
}
return response;
}
}
In workbench I will enter the following Json format for inserting Multiple accounts and each account will have 2 contact records or more..
{
"rb": {
"a": {
"Name": "LG1",
"SLAExpirationDate__c": "2016-4-21",
"Active__c": "Yes",
"SLA__c": "Platinum",
"SLASerialNumber__c": "200"
},
"cList": [{
"FirstName": "K1",
"LastName": "K2"
}, {
"FirstName": "K3",
"LastName": "K4"
}]
},
"b": {
"Name": "LG2",
"SLAExpirationDate__c": "2016-4-21",
"Active__c": "Yes",
"SLA__c": "Platinum",
"SLASerialNumber__c": "200"
},
"cList": [{
"FirstName": "K5",
"LastName": "K6"
}, {
"FirstName": "K7",
"LastName": "K8"
}]
}

Hi PankajI am working with ur code.In workbench this is my JSON input.{ "rb" : { "a" :{ "Name" : "Account1", "SLAExpirationDate__c" : "2016-4-21", "Active__c" : "Yes", "SLA__c" : "Platinum", "SLASerialNumber__c" : "200" }, "cList" : [ {"FirstName" : "K1", "LastName" : "K2"}, {"FirstName" : "K3", "LastName" : "K4"} ]}}error :JSON_PARSER_ERRORmessage: Unknown field: Bulkinsert_accountcontact.lstRBody.a at [line:2, column:11]errorCode: JSON_PARSER_ERRORCould u pls let me know?Pooja Biswas