Create
1 min
To create a Contact in NetSuite, use action as "createContact" and pass the Contact data in the requestJSON under "contacts".
Note: You can only create one record at a time.
The following is an example of createContact where we are setting most of the fields (See Contact for all the available fields). The response will return the response back from NetSuite, which includes the new NetSuite Contact Id (internalId), plus the newly created Salesforce Contact Id (salesforceID)
// Create a Map to store all the data of a Contact
Map<String, Object> nsContact = new Map<String, Object>();
nsContact.put('firstName', 'James');
nsContact.put('lastName','Williams');
nsContact.put('subsidiary', new Map<String, Object>{'internalId'=>'1'});
nsContact.put('email', '[email protected]');
nsContact.put('company', new Map<String, Object>{'internalId'=>'32342'});
nsContact.put('phone', '3453254543');
nsContact.put('officePhone', '6546564564');
nsContact.put('title', 'CEO');
nsContact.put('isPrivate', true);
// Initializing the Contact Custom Fields
List<Object> conCustomFieldList = new List<Object>();
Map<String, Object> conCustomField1 = new Map<String, Object>();
conCustomField1.put('fieldType', 'boolean');
conCustomField1.put('scriptId', 'custentity_f3_mm_send_wf_sms');
conCustomField1.put('value', 'true');
conCustomFieldList.add(conCustomField1);
Map<String, Object> conCustomField2 = new Map<String, Object>();
conCustomField2.put('fieldType', 'string');
conCustomField2.put('scriptId', 'custentity_alt1_email');
conCustomField2.put('value', '[email protected]');
conCustomFieldList.add(conCustomField2);
// Adding the Contact Custom Fields
nsContact.put('customFieldList', new Map<String, Object>{'customField'=>conCustomFieldList});
// Initializing the Contact Addresses
List<Object> addressBookList = new List<Object>();
Map<String, Object> addressBook = new Map<String, Object>();
Map<String, Object> addressbookAddress = new Map<String, Object>();
addressbookAddress.put('addr1', 'Suite 201');
addressbookAddress.put('addr2', '2334 Park Street Avenue');
addressbookAddress.put('city', 'Chicago');
addressbookAddress.put('state', 'IL');
addressbookAddress.put('country', '_unitedStates');
addressbookAddress.put('zip', '60601');
addressBook.put('addressbookAddress', addressbookAddress);
addressBook.put('defaultBilling', true);
addressBook.put('defaultShipping', true);
addressBookList.add(addressBook);
nsContact.put('addressbookList', new Map<String, Object>{'addressbook'=>addressBookList});
// Initializing the RequestJSON Data to be passed.
Map<String, Object> requestJSONMap = new Map<String, Object>();
requestJSONMap.put('contacts', new List<Object>{nsContact});
String reqJSON = JSON.serialize(requestJSONMap);
Map<String, Object> reqObj = new Map<String, Object>();
reqObj.put('version', '1.0');
reqObj.put('action', 'createContact');
reqObj.put('requestJSON', reqJSON);
// Placing a request to Breadwinner Global API
Map<String, Object> resp = breadwinner_ns.BreadwinnerNetSuiteAPI.call(reqObj);
System.debug(resp);