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


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


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


To learn more about custom fields, check this doc: NetSuite Custom Fields