A common question from customers setting up or expanding their integration with Salesforce and TrueContext is how to use a single destination to both create and update an object in Salesforce.
In this example, I will focus on work orders, but the same methods apply to any object. The key is configuring your Update Query to check for the existing object to update; if it does not exist, it will create a new one. If you've tried this before, you may have met the error: “There was an error with the Salesforce API call: SOQL statements cannot be empty or null.” The error shows what went wrong, and I'll explain how to resolve it.
Salesforce Destination: Update Query
The Update Query tab in your Salesforce destination defines the conditions under which a record is updated or created. Our documentation explains several options, but I’ll use “Update if exists, otherwise create new” for this example.
When building forms for Salesforce integration, include all relevant Salesforce IDs to update the records in your data source. For instance, if updating an account, pull in the AccountId; for contacts, include the ContactId. In this case, I'll pull in the WorkOrderId into my form (note that all Salesforce IDs are case-sensitive). In the form, my Workorder ID is called WOID and here is a simple example of the destination that I am using with this:

I am using the Workorder ID to check for matches and if it finds a workorder with the same ID as the one in the form it will update that. If a match is found, it will pass the Description, Priority, and Subject to update the record. If no workorder is found with that ID, it will create a new workorder with those same data points.
The Form
In the form, you can't leave the WOID question blank, even when creating a new work order. Salesforce needs a valid 18-character ID; passing a blank value will cause the entire destination to fail with the earlier mentioned error.
To avoid this, use Conditional Logic or set a default value for the WOID question. For example, you can set it to “111111111111111111” (18 ones), which is guaranteed to be invalid in Salesforce. With the default value in place, you can use a dropdown to select an existing work order, which will populate the WOID question with the correct Work Order ID.
Using this technique will help you avoid creating more destinations than you need to and ultimately create a very flexible workflow that will keep all your data in Salesforce up to date as the people in the field are working through their workflows.