Introducing Apex REST APIs as Agent Actions in Salesforce

June 12, 2025
1144 Views
Introducing Apex REST APIs as Agent Actions in Salesforce

At TDX ’25, Salesforce introduced an exciting new Beta feature that lets developers turn their Apex REST APIs into agent actions. This means you can now bring your custom Apex logic right into your AI-powered agents—making them smarter, faster, and more tailored to your business needs.

In this post, we’ll guide you through the process:

  • Learn how to create an OpenAPI document that defines your Apex REST API.
  • Register the OpenAPI document in your Salesforce org’s API Catalog.
  • Convert each API operation into an agent action directly from the OpenAPI spec.

What is an OpenAPI?

OpenAPI is a standard format for describing RESTful APIs. It allows developers to define what an API does, what endpoints it has, what data it accepts/returns, and how it behaves — all in a machine-readable way (usually in YAML or JSON format).

In human terms:

Think of OpenAPI as a blueprint or instruction manual that tells people and computers how to use an API without needing to look at the source code.

Why it matters:

  • Helps developers document APIs easily.
  • Tools can auto-generate code, tests, and interactive docs from it.
  • Standardizes how APIs are described across the industry.

YAML vs JSON

At this point, it’s important to also look at a clear comparison between YAML and JSON.

YAML (YAML Ain’t Markup Language)

YAML is a human-friendly data serialization format often used for configuration files. It emphasizes readability and uses indentation (like Python) to structure data. It’s popular in tools like Docker, Kubernetes, and GitHub Actions.

JSON (JavaScript Object Notation)

JSON is a lightweight data-interchange format that is easy for machines to parse and generate. It’s widely used in APIs and web applications to transmit data between servers and clients.

Comparison Table

Feature YAML JSON
Full Form YAML Ain’t Markup Language JavaScript Object Notation
Definition Human-readable format for data/config Lightweight data-exchange format
Syntax Style Indentation-based, no braces or quotes Uses braces {}, brackets [], quotes
File Extension .yaml or .yml .json
Readability Easier for humans to read/write Structured but less human-friendly
Comments Support Yes (# for comments) No native support
Whitespace Sensitive Yes (indentation matters) No
Used In Configs (e.g., Kubernetes, Ansible) APIs, web apps, config files
Data Types Supports lists, maps, scalars, anchors Objects, arrays, numbers, strings
Parsing Complexity More complex Simple and widely supported
YAML and JSON Example
YAML and JSON Example

What is Apex REST API in Salesforce?

The Apex REST API allows developers to expose custom Apex classes and methods as RESTful web services. This is useful when you want to let external systems interact with your Salesforce org using HTTP methods like GET, POST, PUT, DELETE.

Key Concepts

  • Annotated with @RestResource
  • Uses HTTP methods: @HttpGet, @HttpPost, @HttpPut, @HttpDelete
  • Returns data in JSON or XML
  • Accessed via a unique URL

Why Use Apex REST?

  • Build custom API endpoints.
  • Integrate with external systems.
  • Full control over request and response formats.
Also Read

Don’t forget to checkout: Agentforce for HR: Everything You Need to Know.

Create and Configure OpenAPI Document

First, create an OpenAPI document for your Apex REST API using VS Code or Code Builder. Make sure to check the required prerequisites in the documentation. You can generate the document using Agentforce for Developers. Just open the Apex class in your Salesforce DX project and run the command:

SFDX: Create OpenAPI Document from This Class (Beta)
Create and configure the OpenAPI document

The command generates the files:

  • <ApexClass>.yaml
  • <ApexClass>.externalServiceRegistration-meta.xml
Generated Metadata XML

Generated Metadata XML

Generated Metadata YAML

Generated Metadata YAML 

Validate OpenAPI Document

Validate the OpenAPI Document

Run the following command to check for errors and warnings:

SFDX: Validate OpenAPI Document (Beta)

Then, deploy the generated XML file to your org and confirm the availability of the Agent Action.

Deploy the generated XML
Deploy the generated XML 2

Create an Agent Action

The API and its operations are now exposed as an Apex Reference Action type, which you can use to create a custom Agent Action in your org.

Create an Agent Action

Conclusion

With Apex REST APIs now available as agent actions, Salesforce developers can extend the intelligence and flexibility of AI-powered agents by tapping into existing business logic. This new capability streamlines integration, enhances automation, and allows for more tailored customer interactions—all while staying within the Salesforce ecosystem. As this feature evolves, it promises to unlock even more powerful use cases for Guided Shopping and beyond.

How useful was this post?

Click on a star to rate it!

Average rating 5 / 5. Vote count: 2

No votes so far! Be the first to rate this post.

Written by

Raja Patnaik

With over a decade of experience in Salesforce, I specialize in crafting smart solutions for industries like real estate, healthcare, banking, and payments. As director of Technology Architecture at RafterOne, I help businesses grow and streamline operations by building powerful B2B Commerce solutions on Salesforce. I’m passionate about turning ideas into reality—from gathering business needs to designing, developing, and launching solutions that create real value. I’ve had the opportunity to lead projects integrating tax, shipping, and payment systems into e-commerce platforms, improving workflows and customer experiences. A highlight of my work has been automating CPQ and billing processes using the Lightning B2B Store. I'm also honored to serve on the Salesforce B2B Commerce Partner Advisory Board, contributing to the evolution of future products. I love learning and staying ahead of the curve, focusing on solving complex problems and driving meaningful results for businesses.

Get the latest tips, news, updates, advice, inspiration, and more….

Contributor of the month
contributor
Gopinath G

Passionate about the intersection of cutting-edge technologies

...
Categories
...
Boost Your Brand's Visibility

Want to promote your products/services in front of more customers?

...

Leave a Reply

Your email address will not be published. Required fields are marked *