Update or create action

An update or create action changes an existing record in your target application if it exists, but creates the record if it doesn't exist. This action is also known as an upsert (update or insert) action.

For example, a contact 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 make sure that you're updating the correct information.

If more than one record in your target system matches your criteria, you see an error for the flow on the Design page. The flow doesn't update or create any records. For example, maybe you have more than one contact with the same given name and surname. So, you can try to match a contact by using unique data, such as their email address.

Figure 1. Update or create contact action for Salesforce
Update or create contact action for Salesforce

After you specify 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 exists, the values that you specify overwrite existing values in the target application. If you don't want to update a value, don't enter a value in the field 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 get the same results (see the following information about idempotence). This behavior is 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 as follows.
  • 200 means that a record was updated
  • 201 means that a record was created
  • 204 means that 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 that depend on whether a record was updated or created. By adding an If node, you can indicate what action to take 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 is returned for a Salesforce Update or create contact action. (The value can be set to 200, 201, or 204 as required.)

Figure 2. Selecting the status code for an update or create action
Selecting the status code for an update or create action

You can find a list of available update or create actions by searching for update or create on the Applications and APIs page.

Idempotence of the update or create action

When you're choosing the actions to include in your flow, consider a scenario when the request to the external system fails and App Connect retries the request. Some application actions are idempotent. They can be completed many times without different outcomes). Other actions are not idempotent. If they're completed more than once, the system might be in a different state than if the action was carried out only once. For example, if you use the Salesforce Create lead action, App Connect can repeat this action for a particular record. Maybe the Salesforce system took too long to respond. Because Create lead is not an idempotent action, you might find that you have some duplicate leads when the process is complete. Instead, you can choose an idempotent action such as Update or create lead. You can then configure the action so that it creates a lead only if an equivalent lead doesn't exist in your Salesforce account. Therefore, if the action is tried one time or five times, you still have the exact number of leads that you retrieved from your source system.

Example

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.