1// Start Future Method Class called from Trigger 'BW_AccountTrigger'
2public class WriteNetSuiteCustomerFuture {
3 @future (callout=true)
4 public static void updateNetSuiteCustomer(String accountRecords) {
5 List<Account> accountList = new List<Account>();
6 try{
7 accountList = (List<Account>)JSON.deserialize(accountRecords , List<Account>.class);
8 Map<String, String> mapOfAccountIdVsNetSuiteCustomerInternalId = new Map<String, String>();
9 for(breadwinner_ns__BW_Company__c accountVar:[Select Id, breadwinner_ns__InternalId__c, breadwinner_ns__Salesforce_Account__c From breadwinner_ns__BW_Company__c Where breadwinner_ns__Entity_Type__c = 'Customer' AND breadwinner_ns__Salesforce_Account__c IN : accountList ]){
10 mapOfAccountIdVsNetSuiteCustomerInternalId.put(accountVar.breadwinner_ns__Salesforce_Account__c, accountVar.breadwinner_ns__InternalId__c);
11 }
12 List<Object> netSuiteCustomerList = new List<Object>();
13
14 // Iterate over all the passed in Account records
15 for(Account accountVar : accountList){
16 Map<String, Object> netSuiteCustomerMap = new Map<String, Object>();
17 // Assign the values of Account to NetSuite Customer
18 if(mapOfAccountIdVsNetSuiteCustomerInternalId.containskey(AccountVar.Id)) {
19 netSuiteCustomerMap.put('internalId',mapOfAccountIdVsNetSuiteCustomerInternalId.get(AccountVar.Id));
20 netSuiteCustomerMap.put('companyName',accountVar.Name);
21 netSuiteCustomerList.add(netSuiteCustomerMap);
22 }
23 }
24
25 Map<String, Object> reqJSONMap = new Map<String, Object>();
26 reqJSONMap.put('customers' , netSuiteCustomerList);
27 String reqJSON = JSON.serialize(reqJSONMap);
28
29 Map<String, Object> finalReqMap = new Map<String, Object>();
30 finalReqMap.put('version' , '1.0');
31 finalReqMap.put('action' , 'updateCustomer');
32 finalReqMap.put('RequestJSON' , reqJSON);
33 System.debug('Request ::: ' + finalReqMap);
34
35 Map<String, Object> respMap = breadwinner_ns.BreadwinnerNetSuiteAPI.call(finalReqMap);
36 System.debug('Response ::: ' + respMap);
37 }catch(Exception e) {
38 System.debug('Exception Error ::: ' + e);
39 }
40 }
41}
42// End Future Method Class called from Trigger "BW_AccountTrigger"