How to Build AI Agents in Salesforce with Agentforce Custom Actions?

Article Written By:
Varalatchumi V
Created On:

February 25, 2026

Salesforce admin building Agentforce custom actions with Flow and Apex in Agent Builder

To build AI agents in Salesforce with Agentforce custom actions, you package your business logic as an Autolaunched Flow, Invocable Apex, or a prompt template, register it as an action in Agent Builder, then write plain-language instructions that tell the agent when to run it. Custom actions are the "hands" that let an autonomous agent read data, run a workflow, and update records without a human clicking through every step.

Standard actions cover the basics. The real power of Agentforce shows up when you build custom actions tuned to your own data and processes. This guide walks through the full build—Flow, Apex, testing, and the permissions that trip up most first agents.

What are Agentforce custom actions?

A custom action is a specific task you let an AI agent perform against your Salesforce data and logic. If the Atlas Reasoning Engine is the brain that plans, custom actions are the hands that do the work.

Each action has one clear job: look up an order, create a case, calculate a quote, or draft an email. The agent decides when to call it based on your instructions and the user's request.

Standard actions vs. custom actions

Standard actions ship with Agentforce and handle common jobs like drafting an email or answering from a knowledge article. Custom actions are the ones you build for logic that is unique to your org. For background on how Salesforce frames the agent model, Salesforce Ben's Agentforce coverage is a useful reference.

How actions live inside topics

In Agent Builder, actions don't float on their own. They sit inside topics—job-based groupings like "Order Management" or "Case Handling." A topic holds the instructions plus the actions the agent may use for that job. Get the topic boundaries right and the agent picks the correct action far more often.

Before you build: what you need

Line up a few things first: an Autolaunched Flow or Apex class for your logic, a clear input and output for each action, and a sandbox to test in. You'll also need a permission set for the Einstein Service Agent, which is the identity your agent runs as.

The three ways to build a custom action

You can build a custom action three ways, and picking the right one saves both effort and Flex Credits. Here's how they compare.

Build method Best for Skill level Example use
Salesforce Flow Standard data lookups and record updates Low-code (admin) "Get order status" lookup by order number
Invocable Apex Heavy logic, external API callouts, bulk updates Pro-code (developer) Real-time credit check against an outside system
Prompt Template Generative text tasks grounded in your data Low-code (admin) Summarize a case or draft a reply email


How to build a custom action with Salesforce Flow

Flow is the most common path because it's low-code and fast. Community walkthroughs like Apex Hours show the same pattern in action.

Step 1: Define your inputs and outputs

Start with the data contract. For an "Order Status" action, set Order Number as an input variable and Order Status as an output variable. Mark both as available for input and output so the agent can pass and read them.

Step 2: Build the logic

Add a Get Records element to pull the order that matches the input number. Return the status field to your output variable. Keep the Flow narrow—one action, one job.

Step 3: Register the action in Agent Builder

Open Agentforce Studio, then Agent Actions, then New Action. Choose Flow as the reference type and select your active Autolaunched Flow. Check "Collect data from user" for inputs the agent should ask about, and "Show in conversation" for outputs it should say back.

Step 4: Write the natural language instructions

You don't trigger actions with code here - you trigger them with clear instructions. Write them the way you'd brief a new hire.

  • Strong instruction: "Retrieve the order status and delivery date using the order number the customer provides."
  • Guardrail: "Process refunds only for orders from the last 60 days. Escalate older cases to a human."

How to build a custom action with Invocable Apex

Reach for Apex when the logic is heavy - complex math, multi-object updates, or an external API call. When your action needs to talk to an outside system, sound integration architecture keeps those callouts safe and testable.

You expose the method to the agent with the @InvocableMethod annotation. A minimal example looks like this:

public class GetOrderStatus {
   public class Request {
       @InvocableVariable(required=true)
       public String orderNumber;
   }
   public class Result {
       @InvocableVariable
       public String status;
   }
   @InvocableMethod(label='Get Order Status')
   public static List<Result> run(List<Request> requests) {
       // query the order, set status, return
   }
}

Salesforce's Invocable Apex documentation covers the annotation rules and limits. Once the class is saved, register it in Agent Builder just like a Flow—pick Apex as the reference type.

How to test your Agentforce custom action

Don't ship an agent on a hunch. Use the Agentforce Testing Center to run test utterances—real phrases a user might type—and confirm the agent picks the right action and returns the right data.

Test the messy cases too: vague requests, missing order numbers, and out-of-scope questions. A quick pass through the Trailhead agent modules helps if the testing tools are new to you.

Why is my agent failing? A permissions checklist

If your agent says "I'm on it" but returns nothing, it's almost always a permissions gap. The agent runs as the Einstein Service Agent user, and that user needs explicit access. Work down this checklist.

Access layer What to check Common failure How to fix
Field-Level Security Read access to every field the Flow or Apex touches Agent returns blank fields Grant FLS on the agent's permission set
Sharing (OWD) Record visibility for private objects Agent finds no records Add a sharing rule for the agent user
Object permissions Read, Create, and Edit on target objects Action errors when it writes Enable object CRUD on the permission set
Apex class access Class enabled for the agent user Apex action never runs Add the class to the permission set

Deploy custom actions the right way

Most guides stop at "it works in my sandbox." That's where the engineering discipline starts. Agent metadata—topics, actions, Flows, and Apex—should move through source control and a real release pipeline, not hand-clicks in production.

Version your actions, review them in pull requests, and promote them through sandboxes with automated tests. Governing agents as real software is where our managed services team spends most of its time, because a poorly governed agent burns Flex Credits and user trust fast.

Frequently asked questions

Is Agentforce just a renamed Einstein Copilot?

No. Einstein Copilot needed a human prompt for each step. Agentforce is autonomous—it uses the Atlas Reasoning Engine to plan and run multi-step tasks on its own.

Do I need to know Apex to build custom actions?

No. Most actions are built with Flow, which is low-code. Reach for Apex only when you need complex processing or an external API call.

Can an Agentforce custom action call an external API?

Yes. Use Invocable Apex with a callout, or an External Service, to reach systems outside Salesforce. Plan the authentication and error handling up front.

How many actions should one topic have?

Keep it tight. Too many actions in one topic makes the agent guess. Group only the actions that belong to the same job, and split topics when the list grows.

How much does Agentforce cost?

Agentforce uses a consumption model with Flex Credits. Pricing changes over time, so confirm current rates with your Salesforce account team before you forecast usage. Well-designed actions keep credit consumption down.

Build your first AI agent with Minuscule

Custom actions turn a chatbot into a digital coworker - but only when the logic, testing, and governance are engineered, not improvised. As your strategic engineering partner, Minuscule Technologies designs high-ROI actions, wires them into your systems, and secures them inside the Einstein Trust Layer. Talk to us and let's build an agent that earns its Flex Credits.

Contact Us for Free Consultation
Thank you! We will get back in touch with you within 48 hours.
Oops! Something went wrong while submitting the form.

Recent Blogs

Ready to Architect Your Salesforce Success?

You've seen what's possible. Now, let's make it happen for your business. Whether you need an end-to-end Salesforce solution, a complex integration, or ongoing managed services, our team is ready to deliver.

Schedule a Free Strategic Call