Skip to main content
pooja biswas 님이 #Apex에 질문했습니다
Hi

I have a rest resource where I create multiple accounts and for each account there can be 'N' number of contacts.

For creating multiple account its working but some how I stuck while creating contact.

Pls let me know where I am going wrong.

I have attached the Json response for the rest resource, 

 

@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"

}]

}

Thanks

pooja Biswas
답변 4개
  1. 2016년 4월 18일 오전 3:22
    Hi  Pankaj

    I 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_ERROR

    message: Unknown field: Bulkinsert_accountcontact.lstRBody.a at [line:2, column:11]

    errorCode: JSON_PARSER_ERROR

    Could u pls let me know?

    Pooja Biswas
0/9000