Newer Version Available
AllOrNoneHeader
Version
This header is available in API version 34.0 and later.
Supported Calls
The AllOrNoneHeader header is also supported by Tooling REST API resources that create, update, or delete records. See Use Tooling API with REST.
Usage
By default, if this header isn’t used, a call can save a partial set of records—the records that are processed successfully are saved and records that have failures aren’t saved.
Fields
| Field Name | Type | Description |
|---|---|---|
| allOrNone | boolean | Set to true to cause all record changes to be rolled back if any records in the call have failures. Set to false to enable saving the successful record changes when some records in the call cause failures. |
Sample Code—Java
When using REST, add the AllOrNoneHeader to your HttpRequest instance before you perform a call as follows:
1HttpRequest req = new HttpRequest();
2req.setHeader("AllOrNoneHeader", true);When using SOAP, add the AllOrNoneHeader to the tooling connection before you perform a call as follows:
1toolingConnection.setAllOrNoneHeader(true);This next example shows how to use the AllOrNoneHeader when creating two Apex classes with the Tooling SOAP API. Because the second class doesn’t have the required Body field, the create() call can’t create this class and rolls back the first class. The output is shown after this code sample.
1import com.sforce.soap.tooling.ApexClass;
2import com.sforce.soap.tooling.CustomObject;
3import com.sforce.soap.tooling.DeploymentStatus;
4import com.sforce.soap.tooling.SaveResult;
5import com.sforce.soap.tooling.SoapConnection;
6import com.sforce.ws.ConnectionException;
7
8public class HeaderSample {
9 SoapConnection toolingConnection = null;
10
11 public static void main(String[] args) throws ConnectionException {
12 HeaderSample samples = new HeaderSample();
13 samples.createWithHeader();
14 }
15
16 public HeaderSample() throws ConnectionException {
17 toolingConnection = ToolingLoginUtil.login();
18 }
19
20 public void createWithHeader() throws ConnectionException {
21 String classBody1 = "public class MyFirstClass {\n"
22 + "public string SayHello() {\n"
23 + " return 'Hello';\n" + "}\n"
24 + "}";
25
26 // Create two new Apex Class objects
27 ApexClass apexClass1 = new ApexClass();
28 apexClass1.setBody(classBody1);
29 ApexClass apexClass2 = new ApexClass();
30 // No class body for class2
31
32 ApexClass[] classes = { apexClass1, apexClass2 };
33
34 // Setting the allOrNone header to true to cause
35 // the call to not commit any record if one or more
36 // records in this call have failures.
37 toolingConnection.setAllOrNoneHeader(true);
38
39 // Call create() to add the Apex classes
40 SaveResult[] saveResults = toolingConnection.create(classes);
41 for (int i = 0; i < saveResults.length; i++) {
42 if (saveResults[i].isSuccess()) {
43 System.out.println("Successfully created class.");
44 } else {
45 System.out.println("Error: could not create class.");
46 System.out.println(" The error message is: " +
47 saveResults[i].getErrors()[0].getMessage());
48 System.out.println(" The error status code is: " +
49 saveResults[i].getErrors()[0].getStatusCode() + "\n");
50 }
51 }
52 }
53}This is the output that the sample returns. The first record is rolled back and the second has a failure.
1Error: could not create class
2 The error message is: Record rolled back because not all records were valid and the request was using AllOrNone header
3 The error status code is: ALL_OR_NONE_OPERATION_ROLLED_BACK
4
5Error: could not create class
6 The error message is: Empty script
7 The error status code is: INVALID_FIELD_FOR_INSERT_UPDATE