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

Extend Agents with Apex

+100 Points~10 minsCompleted
Agent Customization with ApexExtend Agents with Apex

Topics

  • When an Agent Needs Apex
  • Invocable Methods
  • Quiz

Looking for help?

Explore Help ResourcesShare Your Feedback
Learning Objectives

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

  • Decide when an agent action needs Apex.
  • Describe how agents call invocable methods.

When an Agent Needs Apex

Most agent actions run a flow or a standard action. Reach for Apex when the logic is complex, when you need to call an external service with custom handling, or when the result has to be computed exactly the same way every time.

  • Flow for record updates and approvals admins maintain.
  • Apex for complex calculations, callouts, and logic that must be deterministic.

Invocable Methods

An agent calls Apex through an invocable method: a static method annotated with @InvocableMethod. Inputs and outputs are described with @InvocableVariable, so the agent knows what to send and what it gets back.

public with sharing class LeadScore {
  @InvocableMethod(label='Score Lead' description='Returns a fit score for a lead')
  public static List<Integer> score(List<Id> leadIds) {
    // compute and return one score per lead
  }
}
Quiz
To complete this unit, you need to answer all the quiz questions correctly.
+100 Points

1When should an agent action use Apex instead of Flow?

2How does an agent call Apex?

Second attempt earns 50 points. Three or more earns 25 points.
Next unit Write an Invocable Apex Action