With the Summer ’10 release, we have added the ability to retrieve the original data that you send in a Bulk API batch. We keep this data around for 7 days just as we keep the job info, batch info and batch result files.
Because you can now directly retrieve the original data, it has become easier to do things like building a CSV file of all records with errors. You can do this without keeping track of the mappings between the original data set and the batches you submitted to the job.
Here is a very simple Java sample showing how you can do this:
1import java.io.File;
2import java.io.FileWriter;
3import java.net.HttpURLConnection;
4import java.net.URL;
5import java.util.ArrayList;
6import com.sforce.async.CSVReader;
7import com.sforce.async.BatchInfo;
8import com.sforce.async.RestConnection;
9import com.sforce.soap.partner.PartnerConnection;
10import com.sforce.ws.ConnectorConfig;
11public class GetErrors {
12/**
13* @param args
14*/
15public static void main(String[] args) {
16try {
17String username = args[0];
18String password = args[1];
19String jobId = args[2];
20ConnectorConfig config = new ConnectorConfig();
21config.setAuthEndpoint("https://login.salesforce.com/services/Soap/u/19");
22config.setUsername(username);
23config.setPassword(password);
24// Instantiating a new partner connection will perform
25// API login and set the session ID in the ConnectorConfig.
26// We don't actually need the PartnerConnection itself.
27PartnerConnection p = new PartnerConnection(config);
28// Build REST API endpoint from Partner endpoint
29String restEndpoint = config.getServiceEndpoint().substring(0, config.getServiceEndpoint().indexOf("Soap"))
30+ "async/19";
31config.setRestEndpoint(restEndpoint);
32RestConnection rc = new RestConnection(config);
33FileWriter out = new FileWriter(new File("errors.csv"));
34boolean headerWritten = false;
35for (BatchInfo b : rc.getBatchInfoList(jobId).getBatchInfo()) {
36if (b.getState().equals(BatchStateEnum.Completed) && b.getNumberRecordsFailed() > 0) {
37URL resultURL = new URL(restEndpoint + "/job/" + jobId + "/batch/" + b.getId() + "/result");
38URL requestURL = new URL(restEndpoint + "/job/" + jobId + "/batch/" + b.getId() + "/request");
39HttpURLConnection resultC = (HttpURLConnection) resultURL.openConnection();
40HttpURLConnection requestC = (HttpURLConnection) requestURL.openConnection();
41resultC.setRequestMethod("GET");
42requestC.setRequestMethod("GET");
43resultC.addRequestProperty("X-SFDC-Session", config.getSessionId());
44requestC.addRequestProperty("X-SFDC-Session", config.getSessionId());
45CSVReader resultR = new CSVReader(resultC.getInputStream());
46CSVReader requestR = new CSVReader(requestC.getInputStream());
47ArrayList resultHeader = resultR.nextRecord();
48ArrayList requestHeader = requestR.nextRecord();
49while (true) {
50ArrayList resultRow = resultR.nextRecord();
51ArrayList requestRow = requestR.nextRecord();
52if (resultRow == null) {
53if (requestRow != null) {
54System.out.println("Result list finish before request list in batch " + b.getId());
55}
56break;
57}
58if (resultRow.get(1).equals("false")) {
59if (!headerWritten) {
60// We don't write out the header until we have at least one error record
61for (String name : requestHeader) {
62out.write(""" + name.replace(""", """") + "",");
63}
64out.write(""errors"n");
65headerWritten = true;
66}
67for (String field : requestRow) {
68if (field == null) {
69out.write(",");
70} else {
71out.write(""" + field.replace(""", """") + "",");
72}
73}
74if (resultRow.get(3) != null) {
75out.write(""" + resultRow.get(3).replace(""", """") + ""n");
76} else {
77out.write("NO ERROR MESSAGEn");
78}
79}
80}
81}
82}
83out.flush();
84out.close();
85} catch (Exception e) {
86// TODO Auto-generated catch block
87e.printStackTrace();
88}
89}
90}You’ll need wsc-19 and a v19 partner jar to run it. Currently the WSC site doesn’t have the partner jar, but you can compile it yourself using WSC and a downloaded partner WSDL file from your org.
- Download a partner WSDL file by logging into your org and go to Setup -> Develop -> API -> Partner WSDL.
- Run something like: java -cp wsc-19.jar com.sforce.ws.tools.wsdlc `pwd`/partner.wsdl `pwd`/partner-19.jar
- Compile the class above and execute it with: java -cp wsc-19.jar:partner-19.jar GetErrors [sfdc_username] [sfdc_password] [jobId]
- The errors will be downloaded into errors.csv. The last column in the file will contain the error message for each row.
Disclaimer: I hacked this together pretty quickly and I haven’t done much testing. This is just meant as an example. If you put this into use, make sure you review and test your code thoroughly.
Also, note that the records will not be ordered the same way as in your original data set.

