1
2// Start Apex Class
3public with sharing class createNSSalesOrderUsingFuture {
4 public createNSSalesOrderUsingFuture() {
5 }
6
7 @InvocableMethod(label='Create NetSuite Sales Order' description='Create NetSuite Sales Order')
8 public static void createNetSuiteSalesOrderUsingFuture(List<Requests> requestList){
9 createNetSuiteSalesOrder(JSON.serialize(requestList));
10 }
11
12 @future(callout = true)
13 public static void createNetSuiteSalesOrder(String requestListJSON){
14 List<Requests> requestList = (List<Requests>)JSON.deserialize(requestListJSON, List<Requests>.class);
15 List<Object> netSuiteSalesOrderList = new List<Object>();
16
17 for(Requests req : requestList){
18 netSuiteSalesOrderList.add(generateNetSuiteSalesOrderMap(req));
19 }
20 // Sending request to NetSuite via exposed Global API
21 Map<String, Object> reqJSONMap = new Map<String, Object>();
22 reqJSONMap.put('salesOrders' , netSuiteSalesOrderList);
23 String reqJSON = JSON.serialize(reqJSONMap);
24
25 Map<String, Object> finalReqMap = new Map<String, Object>();
26 finalReqMap.put('version' , '1.0');
27 finalReqMap.put('action' , 'createSalesOrder');
28 finalReqMap.put('RequestJSON' , reqJSON);
29 System.debug('Request ::: ' + finalReqMap);
30
31 Map<String, Object> respMap = breadwinner_ns.BreadwinnerNetSuiteAPI.call(finalReqMap);
32 System.debug('Response ::: ' + respMap);
33 }
34
35 public class Requests{
36 @InvocableVariable(label='Class' description='Class')
37 public String classification; //lookup
38
39 @InvocableVariable(label='Created From' description='Created From')
40 public String createdFrom; //lookup
41
42 @InvocableVariable(label='Currency' description='Currency')
43 public String currencyRecord; //lookup
44
45 @InvocableVariable(label='Custom Form' description='Custom Form')
46 public String customForm; //lookup
47
48 @InvocableVariable(label='Department' description='Department')
49 public String department; //lookup
50
51 @InvocableVariable(label='Discount Item' description='Discount Item')
52 public String discountItem; //lookup
53
54 //Adding standard Fields
55 @InvocableVariable(label='Terms' description='Terms')
56 public String terms;
57 }
58
59 public static Map<String, Object> generateNetSuiteSalesOrderMap(Requests req){
60 Map<String, Object> netSuiteSalesOrderMap = new Map<String, Object>();
61 // Assign values from the Request to NetSuite Sales Order
62 // Initialize the standard Fields
63 If(req.terms!= NULL)
64 netSuiteSalesOrderMap.put('terms', new Map<String, Object>{'internalId'=>req.terms});
65
66 If(req.classification != NULL)
67 netSuiteSalesOrderMap.put('classification', new Map<String, Object>{'internalId'=>req.classification});
68
69 If(req.currencyRecord != NULL)
70 netSuiteSalesOrderMap.put('currencyRecord', new Map<String, Object>{'internalId'=>req.currencyRecord});
71
72 If(req.customForm != NULL)
73 netSuiteSalesOrderMap.put('customForm', new Map<String, Object>{'internalId'=>req.customForm});
74
75 If(req.createdFrom != NULL)
76 netSuiteSalesOrderMap.put('createdFrom', new Map<String, Object>{'internalId'=>req.createdFrom});
77
78 If(req.department != null)
79 netSuiteSalesOrderMap.put('department', new Map<String, Object>{'internalId'=>req.department});
80
81 return netSuiteSalesOrderMap;
82 }
83}