Sales Order Flow
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.
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
Step 3: Click on Next, it will navigate to the Fields selection page. Click on Generate Apex.
Step 4: Copy the generated Apex Class / Apex Test Class (optional). Save/Deploy the copied code to the respective org.
Step 1: Navigate to Salesforce Setup > Flows > New Flow > Record-Triggered Flow
Step 2: Choose the options similar to those mentioned below, and click on Done.
- Select the Object (Opportunity)
- Trigger Event (record is updated)
- Entry Conditions (like StgaeName is Closed Won)
- Run the Flow for updated records (Only when record is updated to meet the condition requirements)
- Optimize Flow for (Actions and Related Records)
- Check Run Asynchronously path (Only when the option "I will check "Run Asynchronously" (on Record-Triggered flow creation Page)" on Step 2)
Step 3: Get Line Items (Opportunity Products query with Current Record ID (opportunity Id)), and click on Done.
- Select Get Records (from the Data section)
- Select Object for Line Records (Opportunity Product)
- Condition for Query (OpportunityId Equals $Record > Opportunity ID)
- Sorting (Ascending by #SortOrder)
- How Many Records to Store (All Records)
- How to Store (Automatically store all fields)
Step 4: Get NetSuite Company (Customer) Info using the Get Records data action, and click on Done.
- Select Get Records (from the Data section)
- Select Object for Info (NetSuite Company)
- Condition for Query (breadwinner_ns__Salesforce_Account__c Equals $Record > Account ID > Account ID)
- Sorting (Optional)
- How Many Records to Store (Only first record)
- How to Store (Choose fields and Salesforce do the rest and select the below fields for further usage)
- breadwinner_ns__InternalId__c
Step 5: Create an Apex Action using the "Create NetSuite Sales Order" Invocable method
Step 6: Map the Fields to Create Invoice in "Apex Action"
Before you start this step, please refer to the Sales Order fields and their data types while mapping the values i.e. Lookup records will need internal ids.
- Select Object for "Sales Order Line Items" input (Opportunity Product)
- Map the NetSuite Company (Created from Step 4, Eg: {!NetSuite_Company.breadwinner_ns__InternalId__c})
- Map the Line Records to "Sales Order Line Items" (Created from Step 3, Eg: {!GetOpportunityProducts})
- 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.
Step 7: Connect the Flow Steps, Click Save, and Activate
- Connect Record Trigger Flow Section to Get NetSuite Company Information (Run Asynchronously)
- Connect Get NetSuite Company Information to Get Opportunity Products
- Connect Get Opportunity Products to Create Sales Order on Opportunity
Step 1: Select the Opportunity
Step 2: Edit the Opportunity to meet Trigger Criteria (StageName > Closed Won)
Step 3: Evaluate the created Sales Order at NetSuite