Salesforce Flex routing allows you to route a conversation based on custom queries using Salesforce SOQL (Salesforce Object Query Language).
Billing Plan: Salesforce Flex Routing is available for all users on the Advanced FY22 plan and above.
Intended Audience:
In this article, we'll go over:
- What is Salesforce SOQL
- How to use your Salesforce SOQL for Flexible Routing
What is Salesforce SOQL
SOQL stands for Salesforce Object Query Language. You can use SOQL to read information stored in your Salesforce org’s database. SOQL is syntactically similar to SQL (Structured Query Language).
You can write and execute a SOQL query in Apex code or in the Developer Console’s Query Editor to support all objects in Salesforce.
For more info in Salesforce SOQL, check out this help doc from our friends over at Salesforce.
How to use your Salesforce SOQL for Flexible Routing
To use your Salesforce SOQL, you'll want to be in the Conversation Routing screen in Drift. You can access this screen by going to Settings > Conversation Routing.
While in your conversation Routing Rules, you'll want to select your Salesforce routing block. (For more info on using Conversation Routing, check out our help doc here)

From here, you'll be able to add your Salesforce SOQL. To do this:
1. Select the Visitor has an owner check box.

2. Select the Salesforce owner to create a rule that will make a live API check against Salesforce in order to assign chat responsibility to the right teammate in Drift.

3. Select the Object Priority and Field from the dropdown menus to indicate which Salesforce Object Drift should query, and in which user-type field we should look for ownership information. This first step is crucial, as you are setting the foundation for all of the custom filtration that will be entered in the space below these dropdowns.

4. Select the Create custom query radio button.

5. From here, you'll be able to insert your Salesforce SOQL. (Note: when adding fields to your SOQL, we suggest using the + Add Drift field and + Add Salesforce field on the top right hand side of the editor to properly match your fields). This allows you to use things we know about the website visitor in chat, from Drift Intel, and from GEO-IP to be able to customize your SOQL queries to be highly specific, meeting the buyer where they are...literally!


Note: If you are not seeing all of the expected fields in Drift that you need to power your custom queries, ensure the integrations user connecting Drift to Salesforce has all of the requisite fields and objects visible from your Salesforce user permissions and object-level visibility settings. You can verify access to a specific field in Salesforce to confirm this information is available to use for conversation routing in Drift.
6. Click Save
Optionally, you can test your query with a past run conversation by selecting the select conversation drop down beneath your editor in the Test Query field.

This testing can be run by using a recent website visitor's email address, or you can indicate a specific conversation ID to verify expected outcomes from your routing query:

Once completed, your Flexible routing skill will be activated in your conversation routing flow. To select who to route the conversation to, simply select the Route to pulldown on your conversation routing screen and make your selection. For further info on configuring Drift Conversation Routing, check out our doc here.
Best Practices for SOQL Queries
When we look for a relationship between the visitor in chat and your Accounts in Salesforce, usually we check for a related Contact, and then look for Accounts with a website field matching the visitor's email domain, collected from chat. This forms the basis for Account-level lookups, and can be customized to respect additional elements within your Account object such as Territories, Product Specialities, or different Account Owner User Role Names.
When identifying a matching Contact or Lead in Salesforce to find routing information, Drift relies almost exclusively on the visitor's email address to find any matching records, and then select the first record returned in the list via the Salesforce API. Since SOQL queries allow for the "ORDER" function to organize the returned data, you can utilize this as a way to route based on Lead or Contact attributes, but do so where the records are organized by "First/Last Created" or ordered lexically by Salesforce ID if you want to select the first from such a list. You can also include clauses where specific fields are not null, avoiding records where missing values would indicate an erroneous duplicate or bad-lead.
Each Drift routing node in the global Conversation Routing rules will have a primary outcome, meaning it will route to an individual user in Drift and then either initiate live-chat, or book a meeting on that user's calendar, or fall back to another conditional behavior to keep the website visitor appropriately engaged. Because these rules cannot create branching outcomes, it may become necessary to create a variety of individual SOQL queries on their own nodes, so that certain query returns can trigger unique outcomes in chat. Keep in mind that Drift can offer visitors a variety of experiences, so if you feel constrained to a single query, ask yourself if you could solve the problem by adding a subsequent node, or fallback behavior.
Many customers elect to use Drift's feature to test conversation routing with SOQL rules before implementing them to actually affect the outcome of routing events. This test feature can be configured in the routing settings when building your rule, and will allow the results of your custom SOQL query to be shown in the Routing Audit Log :

Routing Audit Log showing the outcome of these test rules incrementally across example conversations:

Examples
Imagine if you wanted to route conversations to the Salesforce owner, but only for contacts with a certain status in a custom field you created, AND where their Contact Owner is one of your Drift Chat users. This SOQL query references values on the Contact related to who is managing their relationship, as well values related to their current Opportunity status (surfaced on a custom field in this example).

For a more advanced example, you could look at relationships between Drift Chat users at a fundamental relationship level within Salesforce. If you had a prioritized Account in live chat, and perhaps the Account Owner was not available at the moment, but you wanted to make a fallback rule to allow those chats to route to the Account Owner's manager (listed on their User in Salesforce) then this nested SOQL query will allow you to do so. As you can see, we nest a simple "query for ownerID by Account" in side a query for the User related to that Account's ownership, then ultimately route the chat to the Manager as selected on the Object Priority and Field Dropdowns at the top:

Opportunity Amount, or different values found on the Opportunity object, can be a great way to decide who should be routed into chat. Certain deals may be rock-solid, and expressed as such in a confidence percentage or a stage value that indicates they are close to touchdown. Other deals might have values on the Opportunity that indicate a certain escalation should take place in chat, or that a specified teammate is responsible for a certain part of the deal cycle. In order to accelerate deal cycles, finding that teammate with a custom SOQL query can be an important step in making sure the customer talks to the exact right person, at the right moment in the buying journey:

Salesforce Flexible Routing is not just for Sales use-cases either! You can customize your routing outcomes based on different service-plan levels, making sure that your premier customers receive the most immediate help while other customers are served resources or directed to log a ticket or create a Case for follow-up:

Another example, this time by Case status to route where the Priority is elevated beyond where we would want to fallback to a meeting booking.

The benefit of identifying standard Salesforce objects by a custom value or field is to orchestrate the routing outcome to align to your business goals, SLAs, or KPIs associated with teammate performance. In this example of routing Ultra High priority Support conversations, you might consider an outcome such as the one below to force Cases of this priority to the queue of an assigned user, in order that they engage with these most urgent requests:
