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