Global API
...
Code Examples
Sales Order Flow
Class (Edit NetSuite Sales Order)
1min
Apex
Apex Test
1// Start Apex Class
2public with sharing class editNSSalesOrderRunAsync {
3 public editNSSalesOrderRunAsync() {
4 }
5
6 @InvocableMethod(label='Edit NetSuite Sales Order' description='Edit NetSuite Sales Order')
7 public static List<Response> editNetSuiteSalesOrder(List<Requests> requestList){
8 List<Response> resToBeReturnedList = new List<Response>();
9 List<Object> netSuiteSalesOrderList = new List<Object>();
10
11 for(Requests req : requestList){
12 netSuiteSalesOrderList.add(generateNetSuiteSalesOrderMap(req));
13 }
14 // Sending request to NetSuite via exposed Global API
15 Map<String, Object> reqJSONMap = new Map<String, Object>();
16 reqJSONMap.put('salesOrders' , netSuiteSalesOrderList);
17 String reqJSON = JSON.serialize(reqJSONMap);
18
19 Map<String, Object> finalReqMap = new Map<String, Object>();
20 finalReqMap.put('version' , '1.0');
21 finalReqMap.put('action' , 'updateSalesOrder');
22 finalReqMap.put('RequestJSON' , reqJSON);
23 System.debug('Request ::: ' + finalReqMap);
24
25 Map<String, Object> respMap = breadwinner_ns.BreadwinnerNetSuiteAPI.call(finalReqMap);
26 System.debug('Response ::: ' + respMap);
27
28 return resToBeReturnedList;
29 }
30
31 public class Requests{
32
33 @InvocableVariable(label='Internal Id' description='Internal Id')
34 public String internalId;
35
36 @InvocableVariable(label='Order Status' description='Order Status')
37 public String orderStatus;
38
39 //Sales Order Line items
40 @InvocableVariable(label='Sales Order Line Items' description='Sales Order Line Items')
41 public List<SObject> soLines;
42
43 @InvocableVariable(label='Line Description' description='Line Description')
44 public String lineDescription;
45
46 @InvocableVariable(label='Line Number' description='Line Number')
47 public String Line;
48
49 @InvocableVariable(label='isClosed' description='Is Closed')
50 public String isClosed;
51
52
53 }
54 public class Response{
55 @InvocableVariable(label='status Code' description='Status of the request')
56 public string statusCode;
57
58 @InvocableVariable(label='SF Record Id' description='SF Record Id')
59 public Id recordId;
60
61 @InvocableVariable(label='Error' description='Error')
62 public String error;
63 }
64
65 public static Map<String, Object> generateNetSuiteSalesOrderMap(Requests req){
66 Map<String, Object> netSuiteSalesOrderMap = new Map<String, Object>();
67 // Assign values from the Request to NetSuite Sales Order
68
69 If(req.internalId != NULL)
70 netSuiteSalesOrderMap.put('internalId',req.internalId);
71
72 If(req.orderStatus != NULL)
73 netSuiteSalesOrderMap.put('orderStatus',req.orderStatus);
74
75 if(req.soLines != null){
76 // Initializing the Sales Order Line Items
77 List<Object> lineItemList = new List<Object>();
78 for(SObject sobj : req.soLines){
79 Map<String, Object> lineItemMap = new Map<String, Object>();
80
81 if(req.lineDescription != null)
82 lineItemMap.put('description', sobj.get(req.lineDescription));
83
84 if(req.Line != null)
85 lineItemMap.put('line',sobj.get(req.Line));
86
87 if(req.isClosed != null)
88 lineItemMap.put('isClosed',sobj.get(req.isClosed));
89
90 lineItemList.add(lineItemMap);
91 }
92 // Adding the Line Items to Sales Order
93 Map<String, Object> LineItemObjMap = new Map<String, Object>();
94 LineItemObjMap.put('item',lineItemList);
95 LineItemObjMap.put('replaceAll',false);
96 netSuiteSalesOrderMap.put('itemList',LineItemObjMap);
97
98 }
99 return netSuiteSalesOrderMap;
100 }
101 }
Updated 09 May 2023
Did this page help you?