Tutorial - Building Your First ACP Flow
A step-by-step guide to creating a Salesforce Flow that uses an Agentforce Context Protocol (ACP) backed Invocable Action to send a Slack notification for new Leads.
Introduction
This tutorial will walk you through creating a simple but practical Salesforce Flow: sending an automated Slack notification whenever a new Lead is created. We’ll use an Agentforce Context Protocol (ACP) backed Invocable Action that interacts with Slack.
This example demonstrates how easily you can integrate ACP’s capabilities into your standard Salesforce automation processes.
Goal
When a new Lead is created in Salesforce, automatically post a message to a designated Slack channel with some details about the new Lead.
Prerequisites
-
An ACP Slack Action:
- You need an Invocable Apex Action that can send Slack messages via ACP. For this tutorial, we’ll assume you have one with the following characteristics:
- Apex Class: e.g.,
ACPSlackActions
- Invocable Method Label: “ACP Slack: Send Message”
- Input Parameters:
channelId
(Text): The ID of the Slack channel to post to.messageText
(Text): The content of the message.
- Output Parameters (Optional but good practice):
success
(Boolean): Indicates if the message was sent successfully.errorMessage
(Text): Contains an error message ifsuccess
is false.
- Apex Class: e.g.,
- Ensure the ACP Connection for Slack is configured and active.
- You need an Invocable Apex Action that can send Slack messages via ACP. For this tutorial, we’ll assume you have one with the following characteristics:
-
Slack Channel ID:
- Know the ID of the Slack channel where you want to post notifications. You can usually find this in Slack (e.g., by looking at the channel details or its URL). For testing, a non-critical channel is recommended.
-
Salesforce Permissions:
- Ability to create/edit Flows.
- Permissions to create Leads (for testing).
Steps to Build the Flow
1. Create a New Record-Triggered Flow
a. Navigate to Setup > Flows. b. Click New Flow. c. Select Record-Triggered Flow and click Create. d. Configure the trigger:
- Object:
Lead
- Trigger the Flow When:
A record is created
- Set Entry Conditions:
None
(or you can add conditions likeStatus
equalsOpen - Not Contacted
if needed). - Optimize the Flow for:
Actions and Related Records
(This is generally suitable for this type of Flow). e. Click Done.
(Placeholder image)
2. Add the ACP Slack Action
a. On the Flow canvas, click the + icon on the path after the Start element. b. Select Action from the elements list. c. In the “Action” search box, type the label of your ACP Slack action (e.g., “ACP Slack: Send Message”). d. Select your action from the list.
3. Configure the ACP Slack Action
a. Label: Give this action instance a descriptive name, like “Notify Slack about New Lead”. b. API Name: This will be auto-generated. c. Set Input Values:
channelId
:- Toggle “Include”.
- Enter the actual Slack Channel ID where you want to post the message (e.g.,
C0123456789
). For a real-world scenario, you might store this in a Custom Setting or Custom Metadata Type and retrieve it in the Flow.
messageText
:- Toggle “Include”.
- We’ll construct a dynamic message. Click in the value field and select New Resource.
- Resource Type:
Text Template
- API Name: e.g.,
leadNotificationMessage
- Description: (Optional) Template for the Slack message.
- In the body, switch to “View as Plain Text” if it’s in Rich Text mode.
- Craft your message using merge fields from the Lead record. Click Insert a resource… and find
$Record > Lead
.
(Note: The Salesforce record link formula might need adjustment based on your org’s URL structure. The one above is a common way to construct it.)- Click Done to save the Text Template. The
messageText
input will now be populated with your template.
(Placeholder image)
d. Set Output Values (Optional but Recommended for Robustness):
- If your ACP action returns
success
anderrorMessage
:- Click + New Resource under “Store Output Values”.
- Resource Type:
Variable
- API Name: e.g.,
slackPostSuccess
- Data Type:
Boolean
- Availability Outside the Flow:
Available for output
(or input, as needed) - Click Done.
- Map the action’s
success
output to thisslackPostSuccess
variable. - Repeat for
errorMessage
(Data Type: Text), creating a variable likeslackPostErrorMessage
.
e. Click Done to save the Action element configuration.
4. Save and Activate the Flow
a. Click Save in the Flow Builder. b. Flow Label: e.g., “New Lead Slack Notification (ACP)” c. Flow API Name: (Auto-generated) d. Click Save. e. Click Activate.
Testing the Flow
-
Create a New Lead:
- Go to the Leads tab in Salesforce and create a new Lead.
- Fill in the necessary details (First Name, Last Name, Company, Email, Lead Source).
- Click Save.
-
Check Slack:
- Go to the Slack channel you specified in the Flow.
- You should see a new message with the details of the Lead you just created.
-
Check Flow Run (If Needed):
- If the message doesn’t appear, go to Setup > Flows.
- Click on your Flow’s name.
- Go to the “Runs” related list (or look for debug logs if you ran it in debug mode). This can help you troubleshoot any issues. If you configured output variables for success/error, you could add a Decision element after the Slack action to, for example, create an error log record if
slackPostSuccess
is false.
Enhancements and Considerations
- Error Handling: Add a Decision element after the ACP action to check the
success
output. If false, you could:- Send an email notification to an admin.
- Create a Task for someone to follow up.
- Log the
errorMessage
to a custom object.
- Dynamic Channel ID: Instead of hardcoding the
channelId
, retrieve it from a Custom Setting, Custom Metadata Type, or even a field on a related record. - More Complex Message Formatting: For very rich Slack messages, your ACP tool might need to accept a JSON payload for Slack’s Block Kit, or you might build that JSON in Flow using Text Templates or Apex-defined data types.
- User Context: Be mindful of the user context in which the Flow runs, especially for permissions related to ACP connections and the underlying services. Record-Triggered Flows often run in a system context, but this can vary.
Conclusion
You’ve successfully built a Salesforce Flow that leverages an ACP-backed Invocable Action to automate a real-world task! This tutorial demonstrates the basic principles of integrating ACP tools into your Flows, opening up a vast range of possibilities for extending Salesforce automation to external systems and custom logic.