// Start Future Method Class called from Trigger 'BW_AccountTrigger'
public class WriteNetSuiteCustomerFuture {
@future (callout=true)
public static void updateNetSuiteCustomer(String accountRecords) {
List<Account> accountList = new List<Account>();
try{
accountList = (List<Account>)JSON.deserialize(accountRecords , List<Account>.class);
Map<String, String> mapOfAccountIdVsNetSuiteCustomerInternalId = new Map<String, String>();
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 ]){
mapOfAccountIdVsNetSuiteCustomerInternalId.put(accountVar.breadwinner_ns__Salesforce_Account__c, accountVar.breadwinner_ns__InternalId__c);
}
List<Object> netSuiteCustomerList = new List<Object>();
// Iterate over all the passed in Account records
for(Account accountVar : accountList){
Map<String, Object> netSuiteCustomerMap = new Map<String, Object>();
// Assign the values of Account to NetSuite Customer
if(mapOfAccountIdVsNetSuiteCustomerInternalId.containskey(AccountVar.Id)) {
netSuiteCustomerMap.put('internalId',mapOfAccountIdVsNetSuiteCustomerInternalId.get(AccountVar.Id));
netSuiteCustomerMap.put('companyName',accountVar.Name);
netSuiteCustomerList.add(netSuiteCustomerMap);
}
}
Map<String, Object> reqJSONMap = new Map<String, Object>();
reqJSONMap.put('customers' , netSuiteCustomerList);
String reqJSON = JSON.serialize(reqJSONMap);
Map<String, Object> finalReqMap = new Map<String, Object>();
finalReqMap.put('version' , '1.0');
finalReqMap.put('action' , 'updateCustomer');
finalReqMap.put('RequestJSON' , reqJSON);
System.debug('Request ::: ' + finalReqMap);
Map<String, Object> respMap = breadwinner_ns.BreadwinnerNetSuiteAPI.call(finalReqMap);
System.debug('Response ::: ' + respMap);
}catch(Exception e) {
System.debug('Exception Error ::: ' + e);
}
}
}
// End Future Method Class called from Trigger "BW_AccountTrigger"