1// Create a Map to store all the data of a Vendor
2Map<String, Object> nsVendor = new Map<String, Object>();
3 nsVendor.put('companyName', 'Pyramid Construction Inc.');
4 nsVendor.put('currencyRecord', new Map<String, Object>{'internalId'=>'1'});
5 nsVendor.put('payablesAccount', new Map<String, Object>{'internalId'=>'114'});
6 nsVendor.put('subsidiary', new Map<String, Object>{'internalId'=>'1'});
7 nsVendor.put('terms', new Map<String, Object>{'internalId'=>'6'});
8 nsVendor.put('url', 'https://www.pyramid.com');
9
10// Initializing the Vendor Custom Fields
11 List<Object> vendCustomFieldList = new List<Object>();
12 Map<String, Object> vendCustomField1 = new Map<String, Object>();
13 vendCustomField1.put('fieldType', 'select');
14 vendCustomField1.put('scriptId', 'custentity_atlas_pbcs_category');
15 vendCustomField1.put('valueLookup', new Map<String, Object>{'internalId'=>'1'});
16 vendCustomFieldList.add(vendCustomField1);
17 Map<String, Object> vendCustomField2 = new Map<String, Object>();
18 vendCustomField2.put('fieldType', 'date');
19 vendCustomField2.put('scriptId', 'custentity_renewal_date');
20 vendCustomField2.put('value', String.valueOf(DateTime.newInstance(2020, 12, 31).getTime()/1000));
21 vendCustomFieldList.add(vendCustomField2);
22
23// Adding the Vendor Custom Fields
24 nsVendor.put('customFieldList', new Map<String, Object>{'customField'=>vendCustomFieldList});
25
26// Initializing the Vendor Addresses
27 List<Object> addressBookList = new List<Object>();
28 Map<String, Object> addressBook = new Map<String, Object>();
29 Map<String, Object> addressbookAddress = new Map<String, Object>();
30 addressbookAddress.put('addr1', '2334 N. Michigan Avenue, Suite 1500');
31 addressbookAddress.put('city', 'Chicago');
32 addressbookAddress.put('state', 'IL');
33 addressbookAddress.put('country', '_unitedStates');
34 addressbookAddress.put('zip', '60601');
35
36 addressBook.put('addressbookAddress', addressbookAddress);
37 addressBook.put('defaultBilling', true);
38 addressBook.put('defaultShipping', true);
39 addressBook.put('isResidential', true);
40
41 addressBookList.add(addressBook);
42
43 nsVendor.put('addressbookList', new Map<String, Object>{'addressbook'=>addressBookList});
44
45// Initializing the RequestJSON Data to be passed.
46Map<String, Object> requestJSONMap = new Map<String, Object>();
47 requestJSONMap.put('vendors', new List<Object>{nsVendor});
48 String reqJSON = JSON.serialize(requestJSONMap);
49
50Map<String, Object> reqObj = new Map<String, Object>();
51 reqObj.put('version', '1.0');
52 reqObj.put('action', 'createVendor');
53 reqObj.put('requestJSON', reqJSON);
54
55// Placing a request to Breadwinner Global API
56Map<String, Object> resp = breadwinner_ns.BreadwinnerNetSuiteAPI.call(reqObj);
57System.debug(resp);