1

I am trying to deploy contacts from source org. to target org. using Bulk Api. I am able to deploy the records in the xml format but my requirement is to use the JSON with the relationship field records.

E.g. if I am sending contacts then it should map with the parent accounts.

Following is the code which is working with xml body.

//To add a batch to job
Http hAddBatch = new Http();
HttpRequest reqAddJob = new HttpRequest();
reqAddJob.setMethod('POST');
reqAddJob.setEndpoint('https://instance-api.my.salesforce.com/services/async/37.0/job/jobId/batch');
reqAddJob.setHeader('Content-Type', 'application/xml;charset=UTF-8');
reqAddJob.setHeader('X-SFDC-Session', sessionId);
reqAddJob.setBody('<?xml version="1.0" encoding="UTF-8"?><sObjects xmlns="http://www.force.com/2009/06/asyncapi/dataload"><sObject><FirstName>Bulk Contact</FirstName><LastName>First Record</LastName><ReportsTo><sObject><Email>[email protected]</Email></sObject></ReportsTo></sObject></sObjects>');
HttpResponse resAddBatchJob = hAddBatch.send(reqAddJob);
String responseAddBatchJobString = resAddBatchJob.getBody();
System.debug('---- responseAddBatchJobString --- '+responseAddBatchJobString);

I am trying the JSON equivalent of the above request by changing the content type and body with:

reqAddJob.setHeader('Content-Type', 'application/json');
reqAddJob.setBody('[{"LastName":"[Bulk API] Chandan Contact 1 (new batch)","description":"Created from Bulk API","Contacts":{"Account":"0019000001jxxxx"}}]');//Add json values
1
  • 1
    How are field headers mentioned. Please add more details. Jul 27, 2016 at 11:03

1 Answer 1

0

Got the solution..

//To add a batch to job
Http hAddBatch = new Http();

HttpRequest reqAddJob = new HttpRequest();

reqAddJob.setMethod('POST');

reqAddJob.setEndpoint('https://chandanlightning-dev-ed.my.salesforce.com/services/async/37.0/job/jobId/batch');

reqAddJob.setBody('[{"LastName":"Panigrahy","Contacts":{"Email":"[email protected]"}}]');//Add json values

HttpResponse resAddBatchJob = hAddBatch.send(reqAddJob);

String responseAddBatchJobString = resAddBatchJob.getBody();

We should provide the relationship name and an indexed field to map to the target org. in the request JSON.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .