Salesforce to NetSuite Opportunity - Sales Order Broadcast
home
Broadcast changes or created opportunities from Salesforce to NetSuite as Sales Orders in real time. You can use this template to implement a quote to cash process in an enterprise.
The detection criteria and fields to move are configurable. Additional systems can be added to be notified of the changes. Real time synchronization is achieved either by rapid polling of Salesforce or Outbound Notifications that reduce the number of API calls. This template uses Mule batching and watermarking capabilities to capture only recent changes, and to efficiently process large numbers of records.
License Agreement
This template is subject to the conditions of the MuleSoft License Agreement. Review the terms of the license before downloading and using this template. You can use this template for free with the Mule Enterprise Edition, CloudHub, or as a trial in Anypoint Studio.
Use Case
A Salesforce administrator wants to synchronize opportunities in Salesforce that are in the 'Closed Won' stage to NetSuite. In NetSuite, these opportunities become Sales Orders. Each time there is a new opportunity that matches the criteria defined, or if there is a change in an existing one in SalesForce, the integration application detects the changes and inserts or updates the Sales Order in NetSuite. This template can serve as a part of the quote to cash process for an Enterprise.
This application can be used as an example or as a starting point upon which you can build your integration's use case.
This template leverages the Mule batch module, which is divided into Process and On Complete stages. After the integration starts from a scheduler, the application queries for the latest Salesforce updates or creates, and when found, executes the batch job. The application retrieves modified or created opportunities, and also information about a related account and products. This is done because to create a NetSuite sales order, the sales order requires references to a customer and items. Thereafter, the application filters out opportunities that are not 'Closed Won' and don't have an account or at least one product associated with it.
In the batch job's Process phase, the customer corresponding to the source opportunity's account is located in NetSuite. The application uses the companyName property of objects in NetSuite to match a SalesForce counterpart.
This property should contain the Name property of a SalesForce object.
If a customer does not exist in NetSuite, the application creates the customer, so that it's ready to reference later in the sales order.
Then all the products (opportunity line items) associated with the opportunity are upserted into NetSuite as InventoryItem objects. The last step upserts the Sales Order object referencing the customer and items created or updated in the previous steps.
Considerations
To make this template run, there are certain preconditions that must be considered. All of them deal with the preparations in both source and destination systems, that must be made for the template to run smoothly. Failing to do so can lead to unexpected behavior of the template.
Salesforce Considerations
To get this template to work:
- Where can I check that the field configuration for my Salesforce instance is the right one? See: Salesforce: Checking Field Accessibility for a Particular Field.
- Can I modify the Field Access Settings? How? See: Salesforce: Modifying Field Access Settings.
As a Data Source
If the user who configured the template for the source system does not have at least read only permissions for the fields that are fetched, then an InvalidFieldFault API fault displays.
java.lang.RuntimeException: [InvalidFieldFault [ApiQueryFault
[ApiFault exceptionCode='INVALID_FIELD'
exceptionMessage='Account.Phone, Account.Rating, Account.RecordTypeId,
Account.ShippingCity
^
ERROR at Row:1:Column:486
No such column 'RecordTypeId' on entity 'Account'. If you are
attempting to use a custom field, be sure to append the '__c'
after the custom field name. Reference your WSDL or the describe
call for the appropriate names.'
]
row='1'
column='486'
]
]
NetSuite Considerations
As a Data Destination
A customer must be assigned to a subsidiary. In this template, this is done statically and you must configure the property file with subsidiary internalId that is already in the system. You can find this number by entering 'subsidiaries'.
in the NetSuite search field and selecting 'Page - Subsidiaries'. When you click the 'View' next to the subsidiary chosen, you see the ID in the URL line. Use this ID to populate nets.subsidiaryId property in the property file.
Run it!
Simple steps to get this template running.
Running On Premises
In this section we help you run this template on your computer.
Where to Download Anypoint Studio and the Mule Runtime
If you are new to Mule, download this software:
Note: Anypoint Studio requires JDK 8.
Importing a Template into Studio
In Studio, click the Exchange X icon in the upper left of the taskbar, log in with your Anypoint Platform credentials, search for the template, and click Open.
Running on Studio
After you import your template into Anypoint Studio, follow these steps to run it:
- Locate the properties file
mule.dev.properties
, in src/main/resources. - Complete all the properties required per the examples in the "Properties to Configure" section.
- Right click the template project folder.
- Hover your mouse over
Run as
. - Click
Mule Application (configure)
. - Inside the dialog, select Environment and set the variable
mule.env
to the valuedev
. - Click
Run
.
Running on Mule Standalone
Update the properties in one of the property files, for example in mule.prod.properties, and run your app with a corresponding environment variable. In this example, use mule.env=prod
.
Running on CloudHub
When creating your application in CloudHub, go to Runtime Manager > Manage Application > Properties to set the environment variables listed in "Properties to Configure" as well as the mule.env value.
After your app is started, there is no need to do anything else. Each time an opportunity is created or modified, it is automatically synchronized to NetSuite as long as it is 'Closed Won' and has products associated.
Deploying a Template in CloudHub
In Studio, right click your project name in Package Explorer and select Anypoint Platform > Deploy on CloudHub.
Properties to Configure
To use this template, configure properties such as credentials, configurations, etc.) in the properties file or in CloudHub from Runtime Manager > Manage Application > Properties. The sections that follow list example values.
Application Configuration
- page.size
200
- scheduler.frequency
10000
- scheduler.start.delay
100
Watermarking default last query timestamp
- watermark.default.expression
2015-04-01T19:40:27.000Z
Salesforce Connector Configuration
- sfdc.username
bob.dylan@orga
- sfdc.password
DylanPassword123
- sfdc.securityToken
avsfwCUl7apQs56Xq2AKi3X
NetSuite Connector Configuration
- nets.email
email@example.com
- nets.password
password
- nets.account
TSTDRVxxxxxxx
- nets.roleId
9
- nets.appId
77EBCBD6-AF9F-11E5-BF7F-FEFF819CDC9F
- nets.subsidiaryId
1
API Calls
Salesforce imposes limits on the number of API Calls that can be made. However, in this template, only one call per scheduler cycle is done to retrieve all the information required.
Customize It!
This brief guide provides a high level understanding of how this template is built and how you can change it according to your needs. As Mule applications are based on XML files, this page describes the XML files used with this template. More files are available such as test classes and Mule application files, but to keep it simple, we focus on these XML files:
- config.xml
- businessLogic.xml
- endpoints.xml
- errorHandling.xml
config.xml
This file provides the configuration for connectors and configuration properties. Only change this file to make core changes to the connector processing logic. Otherwise, all parameters that can be modified should instead be in a properties file, which is the recommended place to make changes.
businessLogic.xml
The functional aspect of this template is implemented in this XM file, directed by a flow that schedules the Salesforce opportunity creates or updates. The several message processors constitute the actions that fully implement the logic of this template. During the Process stage, each Salesforce opportunity is upserted to the NetSuite system. Before this is possible, the template queries the NetSuite if a customer and items exist and if not, it creates these objects.
endpoints.xml
This file is a flow containing the scheduler that periodically queries Salesforce for updated or created opportunities that meet the defined criteria in the query. This file executes the batch job process with the query results.
errorHandling.xml
This file handles how your integration reacts depending on the different exceptions. This file provides error handling that is referenced by the main flow in the business logic.