1// Create a Map to store all the data of a Customer
2Map<String, Object> nsCustomer = new Map<String, Object>();
3nsCustomer.put('internalId', '121357');
4nsCustomer.put('companyName', 'Grand Hotels & Resorts Ltd');
5nsCustomer.put('customForm', new Map<String, Object>{'internalId'=>'-2'});
6nsCustomer.put('currencyRecord', new Map<String, Object>{'internalId'=>'1'});
7nsCustomer.put('priceLevel', new Map<String, Object>{'internalId'=>'1'});
8nsCustomer.put('receivablesAccount', new Map<String, Object>{'internalId'=>'122'});
9nsCustomer.put('subsidiary', new Map<String, Object>{'internalId'=>'1'});
10nsCustomer.put('startDate', DateTime.newInstance(2020, 12, 2).getTime()/1000);
11nsCustomer.put('terms', new Map<String, Object>{'internalId'=>'5'});
12nsCustomer.put('territory', new Map<String, Object>{'internalId'=>'-5'});
13nsCustomer.put('url', 'https://www.grandhotel.com');
14
15// Initialize the Customer Custom Fields
16List<Object> custCustomFieldList = new List<Object>();
17Map<String, Object> custCustomField1 = new Map<String, Object>();
18custCustomField1.put('fieldType', 'select');
19custCustomField1.put('scriptId', 'custentityrating');
20custCustomField1.put('valueLookup', new Map<String, Object>{'internalId'=>'2'});
21custCustomFieldList.add(custCustomField1);
22
23Map<String, Object> custCustomField2 = new Map<String, Object>();
24custCustomField2.put('fieldType', 'double');
25custCustomField2.put('scriptId', 'custentity_decimal');
26custCustomField2.put('value', '76.89');
27custCustomFieldList.add(custCustomField2);
28
29// Add the Customer Custom Fields
30nsCustomer.put('customFieldList', new Map<String, Object>{'customField'=>custCustomFieldList});
31
32// Initialize the Customer Addresses
33List<Object> addressBookList = new List<Object>();
34Map<String, Object> addressBook = new Map<String, Object>();
35Map<String, Object> addressbookAddress = new Map<String, Object>();
36addressbookAddress.put('addr1','2334 N. Michigan Avenue, Suite 1500');
37addressbookAddress.put('city','Chicago');
38addressbookAddress.put('state','IL');
39addressbookAddress.put('country','_unitedStates');
40addressbookAddress.put('zip','60601');
41
42addressBook.put('addressbookAddress',addressbookAddress);
43addressBook.put('defaultBilling',true);
44addressBook.put('defaultShipping',true);
45addressBook.put('isResidential',true);
46
47addressBookList.add(addressBook);
48
49nsCustomer.put('addressbookList', new Map<String,Object>{'addressbook'=>addressBookList});
50
51// Initialize the RequestJSON Data to be passed.
52Map<String, Object> requestJSONMap = new Map<String, Object>();
53requestJSONMap.put('customers', new List<Object>{nsCustomer});
54String reqJSON = JSON.serialize(requestJSONMap);
55
56Map<String, Object> reqObj = new Map<String, Object>();
57reqObj.put('version', '1.0');
58reqObj.put('action', 'updateCustomer');
59reqObj.put('requestJSON', reqJSON);
60
61// Place a request to Breadwinner Global API
62Map<String, Object> resp = breadwinner_ns.BreadwinnerNetSuiteAPI.call(reqObj);
63System.debug(resp);