zcreate Method
Overview
This article describes the Order Builder zcreate()
method. The zcreate()
method uses the Zuora create()
method to create one or more zObjects
of a specific type. Each zcreate()
call can create only one type of zObject
.
Syntax
There are two versions of the zcreate()
method.
List<zApi.SaveResult> zcreate(List<zObject> zobjects)
List<zApi.SaveResult> zcreate(List<zObject> zobjects, Boolean calloptions)
Input Parameters
The zcreate()
method takes the following input paramteres.
Parameter | Type | Description |
---|---|---|
zobjects | List<zObject> | A list of objects to be created in Zuora |
calloptions | Boolean | Only used for atomic amendment call |
Response
The
zcreate() returns a list of zApi.SaveResult
objects that provide the result of the create()
call.
zApi.SaveResult
The
zApi.SaveResult
has the following properties.
Property | Type | Description |
---|---|---|
Errors | List of zObjects | If the create failed, this contains an array of error objects. |
Id | String | ID of the created object. |
Success | Boolean | If the create was successful, true. Otherwise, false. |
Exceptions
The zcreate()
method throws an exception if there is an error. The following classes are used to catch the exception:
zAPIException
zForceException
zRemoteException
Sample Code
// zApiInstance should be instantiated and the login() method must // have been invoked prior to invoking any other method on the // object try { Zuora.zObject acc = new Zuora.zObject('Account'); acc.setValue('Name', 'Zuora 360 created'); acc.setValue('Currency', 'USD'); acc.setValue('BillCycleDay', 1); acc.setValue('PaymentTerm', 'Net 30'); acc.setValue('Batch', 'Batch1'); acc.setValue('Status', 'Draft'); List<Zuora.zObject> objs = new List<Zuora.zObject> {acc}; List<Zuora.zApi.SaveResult> results = zApiInstance.zcreate(objs); for (Zuora.zApi.SaveResult result : results) { if (result.Success){ //get the newly created id String createdId = result.Id; // more code here... } else { //failure Zuora.zObject[] errors = result.errors; for (Zuora.zObject error : errors) { String errorCode = (String)error.getValue('Code'); String message = (String)error.getValue('Message'); //more code here... } } } } catch (Zuora.zRemoteException ex) { if ('INVALID_FIELD' == ex.code) { // An invalid field was specified //more code here... } else { //more code here... } } catch (Zuora.zAPIException ex) { ex.getMessage(); //more code here... } catch (Zuora.zForceException ex) { //more code here... }