Getting Started

  • What is Trailhead
  • myTrailhead
  • Trailblazer Community
  • Career Growth

Learn

  • Trails
  • Trailmixes
  • Modules
  • Projects

Credentials

  • Superbadges
  • Certifications
  • Maintain Certifications

Salesforce

  • Salesforce.com
  • AppExchange
  • Developers
  • Help Portal
© 2026 Salesforce, Inc. All rights reserved. Privacy Terms of Use Trust Accessibility Cookie Preferences
SalesforceTrailhead
  • Today
Agent Customization with Apex

Write an Invocable Apex Action

+500 Points~10 minsHands-On Challenge
Agent Customization with ApexWrite an Invocable Apex Action

Org:Mindful Goat Playground

Topics

  • Write the Class
  • Add It to Your Agent

Looking for help?

Explore Help ResourcesShare Your Feedback
Learning Objectives

After completing this unit, you'll be able to:

  • Write an invocable Apex method.
  • Add it to an agent as an action.

Write the Class

In your Trailhead Playground, open the Developer Console and create a class named OpportunityHealth.

  1. Click File > New > Apex Class.
  2. Name it OpportunityHealth.
  3. Add an invocable method that takes opportunity IDs and returns a health label for each.
  4. Save the class.
Check ChallengeDemo check

Add It to Your Agent

  1. In Setup, open Agentforce Agents and edit your agent.
  2. In the Sales topic, click New Action and choose Apex.
  3. Select OpportunityHealth and save.
Tip
Write a clear action description. The agent reads it to decide when to use the action.
Check Challenge ProgressDemo check
Previous unitExtend Agents with ApexNext unit Script Deterministic Agent Steps