Global API
Apex Generator
Adding Custom Fields
4min
the code generated using the apex generator doesn't include any custom fields, and we have to add the custom fields into the code manually this document is an example of creating a sales order using an apex generator code the procedure is the same for other transactions in this document, we will explain how to add two different types of custom fields the first type is a primitive data field, which can include strings, booleans, dates, and date times the second type is for reference related data, such as lookup fields that require passing an internal id to add custom fields to the apex generator's code, follow these three steps 1\ open the custom fields tab go to the breadwinner for netsuite tab, click on the custom fields tab, and select the sales order custom fields look for the netsuite api name (script id) and datatype of the custom field you want to add 2\ declare the custom fields fields are declared/added inside the "requests" class so, navigate to the "requests" class, paste the below code snippet inside the "requests" class, and edit it as per the requirement ensure that field label, description, datatype, and variable name match your netsuite custom field apex generator code //adding custom fields @invocablevariable(label='new field label' description='new field description') public string newfield; 	 @invocablevariable(label='referencefieldid label' description='reference field description') public string referencefieldid; the above code adds two custom fields to the requests class 3\ initialize the custom fields and add them to the map custom fields should be initialized inside the "generatenetsuitesalesordermap" method to initialize the custom fields, paste the code snippet below in the "generatenetsuitesalesordermap" method after initializing the variable "netsuitesalesordermap" and edit them as required apex generator code // initialize the custom fields list\<object> socustomfieldlist = new list\<object>(); if(req newfield != null) { 	map\<string,object> socustomfield1 = new map\<string,object>(); 	socustomfield1 put('fieldtype', 'string');//pass datatype correctly 	//pass custom field (scriptid) correctly, it starts with custbody 	socustomfield1 put('scriptid', 'yournscustomfieldapiname'); 	socustomfield1 put('value', req newfield); 	socustomfieldlist add(socustomfield1); } if(req referencefieldid != null) { 	map\<string,object> socustomfield2 = new map\<string,object>(); 	socustomfield2 put('fieldtype', 'select'); 	//pass custom field (scriptid) correctly, it starts with custbody 	socustomfield2 put('scriptid', 'yournscustomfieldapiname'); 	socustomfield2 put('valuelookup', new map\<string,object>{'internalid'=>req referencefieldid}); 	socustomfieldlist add(socustomfield2); } // finally add the custom fields to the "netsuitesalesordermap" netsuitesalesordermap put('customfieldlist', new map\<string,object>{'customfield'=>socustomfieldlist}); note the complete example is given below, and for the sake of code readability and length, a few fields that would auto populate by the apex generator are removed here apex generator code // start apex class public with sharing class createnssalesorderusingfuture { public createnssalesorderusingfuture() { } @invocablemethod(label='create netsuite sales order' description='create netsuite sales order') public static void createnetsuitesalesorderusingfuture(list\<requests> requestlist){ createnetsuitesalesorder(json serialize(requestlist)); } @future(callout = true) public static void createnetsuitesalesorder(string requestlistjson){ list\<requests> requestlist = (list\<requests>)json deserialize(requestlistjson, list\<requests> class); list\<object> netsuitesalesorderlist = new list\<object>(); for(requests req requestlist){ netsuitesalesorderlist add(generatenetsuitesalesordermap(req)); } // sending request to netsuite via exposed global api map\<string, object> reqjsonmap = new map\<string, object>(); reqjsonmap put('salesorders' , netsuitesalesorderlist); string reqjson = json serialize(reqjsonmap); map\<string, object> finalreqmap = new map\<string, object>(); finalreqmap put('version' , '1 0'); finalreqmap put('action' , 'createsalesorder'); finalreqmap put('requestjson' , reqjson); system debug('request ' + finalreqmap); map\<string, object> respmap = breadwinner ns breadwinnernetsuiteapi call(finalreqmap); system debug('response ' + respmap); } public class requests{ @invocablevariable(label='class' description='class') public string classification; //lookup @invocablevariable(label='created from' description='created from') public string createdfrom; //lookup @invocablevariable(label='currency' description='currency') public string currencyrecord; //lookup @invocablevariable(label='custom form' description='custom form') public string customform; //lookup @invocablevariable(label='department' description='department') public string department; //lookup @invocablevariable(label='discount item' description='discount item') public string discountitem; //lookup //adding custom fields @invocablevariable(label='new field label' description='new field description') public string newfield; @invocablevariable(label='referencefieldid label' description='reference field description') public string referencefieldid; } public static map\<string, object> generatenetsuitesalesordermap(requests req){ map\<string, object> netsuitesalesordermap = new map\<string, object>(); // initialize the custom fields list\<object> socustomfieldlist = new list\<object>(); if(req newfield != null) { map\<string,object> socustomfield1 = new map\<string,object>(); socustomfield1 put('fieldtype', 'string');//pass datatype correctly //pass custom field (scriptid) correctly, it starts with custbody socustomfield1 put('scriptid', 'yournscustomfieldapiname'); socustomfield1 put('value', req newfield); socustomfieldlist add(socustomfield1); } if(req referencefieldid != null) { map\<string,object> socustomfield2 = new map\<string,object>(); socustomfield2 put('fieldtype', 'select'); //pass custom field (scriptid) correctly, it starts with custbody socustomfield2 put('scriptid', 'yournscustomfieldapiname'); socustomfield2 put('valuelookup', new map\<string,object>{'internalid'=>req referencefieldid}); socustomfieldlist add(socustomfield2); } // finally add the custom fields to the "netsuitesalesordermap" netsuitesalesordermap put('customfieldlist', new map\<string,object>{'customfield'=>socustomfieldlist}); // assign values from the request to netsuite sales order // initialize the standard fields if(req classification != null) netsuitesalesordermap put('classification', new map\<string, object>{'internalid'=>req classification}); if(req currencyrecord != null) netsuitesalesordermap put('currencyrecord', new map\<string, object>{'internalid'=>req currencyrecord}); if(req customform != null) netsuitesalesordermap put('customform', new map\<string, object>{'internalid'=>req customform}); if(req createdfrom != null) netsuitesalesordermap put('createdfrom', new map\<string, object>{'internalid'=>req createdfrom}); if(req department != null) netsuitesalesordermap put('department', new map\<string, object>{'internalid'=>req department}); return netsuitesalesordermap; } } to learn more about custom fields, check this doc netsuite custom fields docid\ gccxmcxcsjyghql05kush