Creation of Child Custom Object Record
1 min
The following is an example of creating a Child Custom Object Record where we are setting every possible field (See Custom Object for the available fields). The response will return the exact request data plus the new NetSuite Child Custom Object Id (internalId) and the newly created Salesforce Child Custom Object Id (salesforceID).
Here, the Internal Id of the Parent Custom Object Record has to be passed in. Only then will this record be treated as a Child Custom Object Record.
// Create a Map to store all the data of a Custom Object
Map<String, Object> nsCustomObject = new Map<String, Object>();
nsCustomObject.put('name', 'other object record');
nsCustomObject.put('isInactive', false);
// Initializing the Custom Object Custom Fields
List<Object> customObjectCustomFieldList = new List<Object>();
Map<String,Object> parentObjectLookupfield= new Map<String,Object>();
parentObjectLookupfield.put('fieldType', 'string');
parentObjectLookupfield.put('scriptId', 'custrecord239');
parentObjectLookupfield.put('value', '2626');
customObjectCustomFieldList.add(parentObjectLookupfield);
Map<String,Object> customObjectCustomField1 = new Map<String,Object>();
customObjectCustomField1.put('fieldType', 'string');
customObjectCustomField1.put('scriptId', 'cusrecord240');
customObjectCustomField1.put('value', 'Hello World');
customObjectCustomFieldList.add(customObjectCustomField1);
Map<String,Object> customObjectCustomField2 = new Map<String,Object>();
customObjectCustomField2.put('fieldType', 'string');
customObjectCustomField2.put('scriptId', 'custrecord241');
customObjectCustomField2.put('value', '9');
customObjectCustomFieldList.add(customObjectCustomField2);
// Adding the Custom Object Custom Fields
nsCustomObject.put('customFieldList', new Map<String,Object>{'customField'=>customObjectCustomFieldList});
// Initializing the RequestJSON Data to be passed.
Map<String, Object> requestJSONMap = new Map<String, Object>();
requestJSONMap.put('customObjectRecords', new List<Object>{nsCustomObject});
requestJSONMap.put('customObjectID', '196');
String reqJSON = JSON.serialize(requestJSONMap);
Map<String, Object> reqObj = new Map<String, Object>();
reqObj.put('version', '1.0');
reqObj.put('action', 'createCustomObjectRecord');
reqObj.put('requestJSON', reqJSON);
// Placing a request to Breadwinner Global API
Map<String, Object> resp = breadwinner_ns.BreadwinnerNetSuiteAPI.call(reqObj);
System.debug(resp);