An update or create action changes an existing record in your target application if it exists, but creates the record if it doesn’t already exist. It’s also known as an upsert (update or insert) action.
For example, say someone has submitted a Wufoo form with a change of address. If the contact is already in your CRM system, you want to update their address; but if they’re not, you want to add them. Like the retrieve action, when you choose an action to update data in one of your applications, you can add one or more conditions to ensure that you’re updating the right information.
If there’s more than one record in your target system that matches your criteria, you’ll see an error for the flow on the dashboard, and the flow won’t update or create any records. For example, maybe you have more than one contact with the same first and last names. So you could try to match a contact by using unique data, such as their email address.
After specifying your filter conditions, you can complete the fields for the record that you want to update or create in the target application. If a record already exists, the values that you specify will overwrite existing values in the target app; if you donâ€™t want to update a value, you can leave the field blank in App Connect.
When you use a field in a filter condition, you cannot change the value of that field in the record in the target application. The target field uses the value that you specify in the filter condition. This behavior makes the action idempotent: if you repeat the action multiple times, you will get the same results (see more about idempotence below). This is particularly useful when you are synchronizing data between systems.
The status codes that you’re likely to see in response to an update or create action are:
- 200: A record was updated
- 201: A record was created
- 204: No record was found for the filter condition
You can use these response codes later in your flow. Maybe you want to take different actions depending on whether a record was updated or created. By adding an “If” node, you can indicate what action should be performed for either of the status codes.
You can map to the status code that an update or create action returns by expanding the Response info node in the list of available inputs. The following example shows how you can map to a status code that’s returned for a Salesforce “Update or create contact” action. (The value can be set to
204 as required.)
You can find a list of available update or create actions by searching for “update or create” on the Applications tab on the Catalog page.
Idempotence of the update or create action
When youâ€™re choosing which actions to include in your flow, consider what would happen if the request to the external system failed for some reason, and App Connect retried the request. Some application actions are idempotent (they can be carried out many times without different outcomes) and others are not (if they were carried out more than once, the system would be in a different state than if the action was carried out only once). For example, if you use the Salesforce Create lead action in a batch process, this action could be repeated by App Connect for a particular record, say because the Salesforce system took too long to respond. Because Create lead is not an idempotent action, you could potentially find that you have some duplicate leads when the batch process is complete. Instead, we recommend that you choose an idempotent action such as Update or create lead, and configure the action so that it will only create a lead if an equivalent lead doesnâ€™t already exist in your Salesforce account. This way, it doesnâ€™t matter whether the action is tried only once, or five times â€“ you will have the exact number of leads that you retrieved from your source system.
To read about a scenario that uses an update or create action and its response codes, see the tutorial Creating an event-driven flow that updates or creates a contact in Salesforce and updates Asana whenever you receive a form in Wufoo.