---
title: Sales Order Flow
slug: netsuite/sales-order-flow
description: Learn how to use the Custom Apex Generator to automate the creation of Sales Order records in NetSuite through Salesforce. Follow step-by-step instructions to generate an Apex class, create a record-triggered flow, and map fields for seamless Sales Order 
docTags: 
createdAt: 2022-05-13T10:51:48.000Z
---

## Custom Apex Generator

This is an example Invocable Method generated by Breadwinner Apex Generator, which can be invoked by a standard Flow. This is quite useful as it shows how you can use Salesforce standard automation practices to drive NetSuite record creation. Using this format you can extend to Update or Read in a similar fashion.

This basic use case shows how easy it is to create robust automation in Salesforce to facilitate **Sales Order** record creation in **NetSuite**. Extending upon this, using the Global API requests in this help site you can perform many automated retrieves, create, or update functions directly rather than requiring extensive middleware or endpoint processing to perform.&#x20;

::embed[]{url="https://www.youtube.com/watch?v=BkcduEMXynU"}

### Apex Class Generation&#xD;

Navigate to Breadwinner Setup > Tools > Apex Generator

Step 1: Choose the record mode **Create/Edit** on a NetSuite object (**Sales Order**) using a **Flow**

Step 2: Select the option for Run this Flow as

![](https://api.archbee.com/api/optimize/amOMwpmEgToJSqhaSTxXr/3zq-OeDEGI4j084wvbfxa_run-as-image.png)

Step 3: Click on Next, it will navigate to the **Fields&#x20;**&#x73;election page. Click on **Generate Apex**.

![](https://api.archbee.com/api/optimize/amOMwpmEgToJSqhaSTxXr/PyeFuNyBMb3MYebZAKSHv_image.png)

Step 4: Copy the generated Apex Class / Apex Test Class (optional). Save/Deploy the copied code to the respective org.

![](https://api.archbee.com/api/optimize/amOMwpmEgToJSqhaSTxXr/o7FnN6aVMKS6063ZM2leq_copy-apex-class.png)

### NetSuite Sales Order Automation using Flows

**Step 1**: Navigate to Salesforce Setup > Flows > New Flow > Record-Triggered Flow

![](https://api.archbee.com/api/optimize/amOMwpmEgToJSqhaSTxXr/UOjBlPUVaSp2TmBAwWcnA_image.png)

**Step 2**: Choose the **options&#x20;**&#x73;imilar to those mentioned below, and click on **Done**.

1. Select the Object (Opportunity)
2. Trigger Event (record is updated)
3. Entry Conditions (like StgaeName is Closed Won)
4. Run the Flow for updated records (Only when record is updated to meet the condition requirements)
5. Optimize Flow for (Actions and Related Records)&#x20;
6. Check Run Asynchronously path (Only when the option "I will check "Run Asynchronously" (on Record-Triggered flow creation Page)"  on Step 2)

![](https://api.archbee.com/api/optimize/amOMwpmEgToJSqhaSTxXr/WzvN9DV2LPfWVBfj7_wrm_flow-initial-page.png)

**Step 3**: Get Line Items (**Opportunity Products** query with Current Record ID (opportunity Id)), and click on **Done**.

1. Select Get Records (from the Data section)
2.   Select Object for Line Records (Opportunity Product)
3.   Condition for Query (OpportunityId Equals $Record > Opportunity ID)
4.   Sorting (Ascending by #SortOrder)
5.   How Many Records to Store (All Records)
6.   How to Store (Automatically store all fields)

![](https://api.archbee.com/api/optimize/amOMwpmEgToJSqhaSTxXr/_xgNYiza6eV-apnbiwZQw_image.png)

**Step 4**: Get NetSuite Company (Customer) Info using the Get Records data action, and click on Done.

1. Select Get Records (from the Data section)
2.   Select Object for Info (NetSuite Company)
3.   Condition for Query (﻿breadwinner\_ns\_\_Salesforce\_Account\_\_c Equals $Record > Account ID > Account ID)
4. Sorting (Optional)
5.   How Many Records to Store (Only first record)
6.   How to Store (Choose fields and Salesforce do the rest and select the below fields for further usage)
   - breadwinner\_ns\_\_InternalId\_\_c

![](https://api.archbee.com/api/optimize/amOMwpmEgToJSqhaSTxXr/5G8_Hlseza-tqSOIYzKMZ_getcustomer-page.png)

**Step 5**: Create an Apex Action using the "Create NetSuite Sales Order" Invocable method

![](https://api.archbee.com/api/optimize/amOMwpmEgToJSqhaSTxXr/xtlvb5V3MVFnTZBoWCK7L_creataation.PNG)

**Step 6**: Map the Fields to Create Invoice in "Apex Action"

Before you start this step, please refer to the [Sales Order fields](https://docs.breadwinner.com/netsuite/sales-order) and their data types while mapping the values i.e. Lookup records will need internal ids.

1. Select Object for "Sales Order Line Items" input (Opportunity Product)
2. Map the NetSuite Company (Created from Step 4, Eg: \{!NetSuite\_Company.breadwinner\_ns\_\_InternalId\_\_c})
3. Map the Line Records to "Sales Order Line Items" (Created from Step 3, Eg: \{!GetOpportunityProducts})
4. Map the Line Record fields with Salesforce API Names (Field Name, Eg: Description) by coping as mentioned in the below image (Line API Names (2nd image))
   - Please create a formula field on the chosen object (Opportunity Product) to fetch the NetSuite Item Internal Id
   - For other than Opportunity Product, if there is a relation with the Salesforce Product, go with the formula field, else create a custom field to store the NetSuite Item Internal Id.

![](https://api.archbee.com/api/optimize/amOMwpmEgToJSqhaSTxXr/WTLnoyilj1V4wW8u3QPkV_part-1.png)

![](https://api.archbee.com/api/optimize/amOMwpmEgToJSqhaSTxXr/-8b5XzRkFeEYpFjxdMDps_part-2.png)

![](https://api.archbee.com/api/optimize/amOMwpmEgToJSqhaSTxXr/o8tOKtmNJeTpNQaS0YJRx_sc5.png "Line Item Salesforce API Names")

![](https://api.archbee.com/api/optimize/amOMwpmEgToJSqhaSTxXr/GHoi_4exHDLgG-fY00OV-_sc4.png "Fetching NetSuite Item Internal Id")

**Step 7**:  Connect the Flow Steps, Click Save, and Activate

1. Connect **Record Trigger Flow&#x20;**&#x53;ection to **Get NetSuite Company Information** (Run Asynchronously)
2. Connect **Get NetSuite Company Information** to **Get Opportunity Products**
3. Connec&#x74;**&#x20;Get Opportunity Products** to **Create Sales Order on Opportunity&#x20;**

![](https://api.archbee.com/api/optimize/amOMwpmEgToJSqhaSTxXr/Bnd-VcWi4jeunCI0snbR0_sc3.png)

### Triggering NetSuite Sales Order creation

**Step 1**: Select the Opportunity

![](https://api.archbee.com/api/optimize/amOMwpmEgToJSqhaSTxXr/ymr84bccxJQ--b91G7dAC_image.png)

**Step 2**: Edit the Opportunity to meet Trigger Criteria (StageName > Closed Won)

![](https://api.archbee.com/api/optimize/amOMwpmEgToJSqhaSTxXr/e-Z0pBDCC8t5jCaIRjwwX_image.png)

**Step 3**: Evaluate the created Sales Order at NetSuite






















﻿





