Global API
...
Code Examples
Custom Record Type Flow
Class(Create NetSuite CustomObject Record)
1min
Apex
Apex Test
1public with sharing class createNSCustomObjectRecordUsingFuture {
2 public createNSCustomObjectRecordUsingFuture() {
3 }
4
5 @InvocableMethod(label='Create NetSuite Custom Object Record'
6 description='Create NetSuite Custom Object Record'
7 category='Breadwinner'
8 )
9
10 public static void createNSCustomObjectRecordUsingFuture(List<Requests> requestList){
11 createNetSuiteCustomObjectRecord(JSON.serialize(requestList));
12 }
13
14 @future(callout = true)
15 public static void createNetSuiteCustomObjectRecord(String requestListJSON){
16 List<Requests> requestList = (List<Requests>)JSON.deserialize(requestListJSON, List<Requests>.class);
17 List<Object> netSuiteCustomObjectList = new List<Object>();
18
19 for(Requests req : requestList){
20 netSuiteCustomObjectList.add(generateNetSuiteCustomObjectMap(req));
21 }
22 // Sending request to NetSuite via exposed Global API
23 Map<String, Object> reqJSONMap = new Map<String, Object>();
24 reqJSONMap.put('customObjectRecords' , netSuiteCustomObjectList);
25 reqJSONMap.put('customObjectId' , '196');
26 String reqJSON = JSON.serialize(reqJSONMap);
27
28 Map<String, Object> finalReqMap = new Map<String, Object>();
29 finalReqMap.put('version' , '1.0');
30 finalReqMap.put('action' , 'createCustomObjectRecord');
31 finalReqMap.put('RequestJSON' , reqJSON);
32 System.debug('Request ::: ' + finalReqMap);
33
34 Map<String, Object> respMap = breadwinner_ns.BreadwinnerNetSuiteAPI.call(finalReqMap);
35 System.debug('Response ::: ' + respMap);
36 }
37
38 public class Requests{
39 @InvocableVariable(label='NetSuite Custom Object Record Name'
40 description='NetSuite Custom Object Record Name'
41 required=true)
42 public String name;
43
44 @InvocableVariable(label='Is Inactive' description='IS Inactive')
45 public Boolean isInactive;
46
47 @InvocableVariable(label='Parent Field' description='Parent Field')
48 public String custrecord239_string_text; // This field is the lookup field
49 //which is passed as internalId of the parent record
50
51 @InvocableVariable(label='Quantity' description='Quantity')
52 public String custrecord241_string_decimal;
53
54 @InvocableVariable(label='Cost' description='Cost')
55 public String custrecord242_string_currency;
56
57 @InvocableVariable(label='Is purchased' description='Is Purchased')
58 public Boolean custrecord243_boolean_boolean;
59 }
60
61 public static Map<String, Object> generateNetSuiteCustomObjectMap(Requests req){
62 Set<String> standardFieldSet = new set<String>{'name','isInactive','internalId' };
63 Map<String, Object> netSuiteCustomObjectMap = new Map<String, Object>();
64 Map<String,Object> reqMap = (Map<String,Object>) JSON.deserializeUntyped(JSON.serialize(req));
65 List<Object> customObjectCustomFieldList = new List<Object>();
66 for(String field : reqMap.keySet()){
67 if(standardFieldSet.contains(field)) netSuiteCustomObjectMap.put(field,reqMap.get(field));
68 else{
69 Map<String,Object> customObjectCustomField = new Map<String,Object>();
70 customObjectCustomField.put('fieldType', field.split('_')[1]);
71 customObjectCustomField.put('scriptId', field.split('_')[0]);
72 if(field.split('_')[2]=='currency' || field.split('_')[2]=='number' || field.split('_')[2]=='decimal' || field.split('_')[2]=='integer' ) customObjectCustomField.put('value', String.valueOf(reqMap.get(field)).remove(','));
73 else customObjectCustomField.put('value', reqMap.get(field));
74 customObjectCustomFieldList.add(customObjectCustomField);
75 }
76 }
77 netSuiteCustomObjectMap.put('customFieldList', new Map<String,Object>{'customField'=>customObjectCustomFieldList});
78
79 return netSuiteCustomObjectMap;
80 }
81}
Updated 15 May 2023
Did this page help you?