Cross-Object Salesforce Search from Teams Command
A Teams message triggers a SOSL search across Accounts, Contacts, and Opportunities in Salesforce, returning matching results as a formatted reply in the Teams channel.
Provided as-is, without warranty of any kind. Review and test each pattern in a non-production environment before deploying it to live automations. See our Terms.
Overview
This flow enables users to search across multiple Salesforce objects (Accounts, Contacts, and Opportunities) from a single search keyword, then posts a formatted HTML summary to a Microsoft Teams channel. It demonstrates the Salesforce SOSL (Salesforce Object Search Language) cross-object search capability combined with Teams channel messaging.
Use Case
Sales teams and business users often need to quickly look up information across multiple Salesforce objects without switching to the Salesforce UI. This flow provides a one-click search that queries Accounts, Contacts, and Opportunities simultaneously using SOSL, formats the results into a readable HTML report, and posts it to a designated Teams channel for visibility.
The flow is ideal for teams that:
- Sales teams that need quick cross-object lookups without leaving Microsoft Teams
- Business users who want a single keyword search across Accounts, Contacts, and Opportunities
- Organizations standardizing Salesforce visibility inside Teams channels
Flow Architecture
Manually trigger a flow
Manually trigger a flowButton trigger with a required Search_Term text input.
Init varTeamsGroupId
Initialize variableLoads the Teams Group ID from the flowlibs_TeamsGroupId environment variable. Runs in parallel with the other init actions.
Init varTeamsChannelId
Initialize variableLoads the Teams Channel ID from the flowlibs_TeamsChannelId environment variable. Runs in parallel with the other init actions.
Init varSearchTerm
Initialize variableCaptures the search keyword from the trigger input. Runs in parallel with the other init actions.
Execute SOSL Search
Salesforce - Execute SOSL QueryRuns a SOSL query via the Salesforce connector: FIND {searchTerm} IN ALL FIELDS RETURNING Account(Id,Name,Industry,Phone), Contact(Id,Name,Email,Phone), Opportunity(Id,Name,StageName,Amount,CloseDate).
Compose Account Results
ComposeFormats account-specific results from the SOSL response. Runs in parallel with the HTML report compose.
Compose HTML Report
ComposeBuilds a styled HTML summary with search term, total result count, and a raw results preview in a code block. Runs in parallel with the account compose.
Post Search Results to Teams
Microsoft Teams - Post message in a chat or channelPosts the HTML report to the configured Teams channel via the Flow bot.
Environment Variables
| Schema name | Type | Default | Description |
|---|---|---|---|
| flowlibs_TeamsGroupId | String | <configure> | The Microsoft 365 Group ID for the target Teams team. Set this to your destination team's group ID. |
| flowlibs_TeamsChannelId | String | <configure> | The channel ID where search results will be posted. Set this to your destination channel's ID. |
Connectors & Connections
| Connector | API name | Actions used |
|---|---|---|
| Salesforce | shared_salesforce | ExecuteSOSLQuery (cross-object search across Accounts, Contacts, and Opportunities) |
| Microsoft Teams | shared_teams | PostMessageToConversation (post HTML results to channel) |
Note — All connections are referenced as solution connection references; the flow is portable between environments as long as a connection is mapped at import time.
Customization Guide
Almost every realistic variant of this flow can be implemented by changing environment variable values. A few cases require small edits inside the flow definition — those are called out explicitly below.
- Configure environment variables
- Set flowlibs_TeamsGroupId and flowlibs_TeamsChannelId to your Teams team and channel IDs.
- Authorize connections
- Open the flow in the designer and authorize the Salesforce and Teams connections against your tenant.
- Modify SOSL query
- Edit the Execute SOSL Search action to add or remove Salesforce objects and fields from the RETURNING clause.
- Customize HTML report
- Edit the Compose HTML Report action to change the styling, add tables per object type, or swap in adaptive card formatting.
- Turn on the flow
- Toggle the flow state from Off to On once connections and environment variables are configured.
Key Expressions
The flow is intentionally light on Power Fx / WDL gymnastics — the heaviest expressions are the branch-name concatenation and the approval outcome check. They are listed below in the order they appear in the flow.
EXPR.01SOSL query construction
Builds the SOSL query string by injecting the user-supplied search term into the FIND clause.
EXPR.02Result count
Counts the records returned by the SOSL search, defaulting to an empty array when no results are found.
EXPR.03Safe array fallback
Prevents null reference errors when the SOSL search returns no records.
EXPR.04Result preview (first 10)
Limits the raw preview included in the Teams message to the first 10 records to avoid oversized payloads.
Comments
Sign in to join the conversation.
Sign inNo comments yet. Be the first to share your experience with this flow.