Skip to main content

Tempo stimato

Argomenti

Chiedi alla community

Create an Apex Agent Action

Learning Objectives

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

  • Create an Apex Agent Action.
  • Add an Agent Action to a topic.
  • Test the Agent Action.

Build an Apex Agent Action

Now that the Apex is ready, let’s add it to an action. You’ll see where the parameters in the Apex automatically get ported to the action.

  1. Click Setup “” and select Setup.
  2. In the Setup Quick Find box, search for and select Agentforce Assets.
  3. Click the Actions tab.
  4. Click New Agent Action.
  5. For Reference Action Type, select Apex.
  6. For Reference Action Category, select Invocable Method.
  7. For Reference Action, select Check Weather. This is the invocable method.

    Create an Agent Action showing the fields as described above.
  1. For Agent Action Label, leave the prefill, Check Weather, that was pulled from the invocable method label parameter.
  2. For Agent Action API name, leave the automatically generated prefill, Check_Weather.
  3. Click Next.

The next step is to configure the Agent Action. This is where you start to see the benefit of the parameters being set in the Apex.

  1. For Agent Action Instructions, leave the prefill provided from the Apex invocable method description parameter.
  2. Un-check Show loading text for this action.
  3. For Input, notice that dateToCheck is prefilled.
  4. For Instructions, note that it’s prefilled with the Apex invocable variable description parameter. You can also update or add to the instructions as necessary.
  5. For Data Type, it’s prefilled with the Apex data type.
  6. Required input is defaulted to checked from the required parameter set to true.
  7. Check Collect data from user.

    Input section filled out as described in the content.
  1. For Outputs, there are three that got pulled from the Apex invocable variables, maxTemperature, minTemperature, and temperatureDescription. The Instructions for each are prefilled from the corresponding description parameters and Data Type.
  2. For the third output, temperatureDescription, check Show in conversation.

    Output 3 filled out as described above with Show in conversion checked.
  1. Click Finish.

Excellent! The action is complete. You now know what it takes to add your Apex to actions. And you have a better understanding of how the Apex parameters work to help build out the action. Let’s add the Check Weather Agent Action to a topic and test it.

Update the Topic

  1. Click Setup “” and select Setup.
  2. In the Setup Quick Find box, search for and select Agentforce Agents.
  3. Select Einstein Copilot or Agentforce (Default).
  4. Click Open in Builder.
  5. Ensure the agent is deactivated.
  6. Select MigrationDefaultTopic.
  7. Click This Topic’s Actions.
  8. Click New, and select Add from Asset Library.
  9. Check the box for the Check Weather action, and click Finish.
  10. Refresh your browser window and then select MigrationDefaultTopic.
  11. Click This Topic’s Actions and verify Check Weather action is still in the list. If it isn’t, repeat steps 8 to 11. Sometimes in our practice environments, an added action doesn’t stay associated with the topic the first time you save it.
  12. Click Activate.

Let’s Check the Weather

  1. While still in Agentforce Builder, enter Check the weather for tomorrow in the Conversation Preview.

    Conversation pane showing the request to Check the weather for tomorrow and the response from the agent showing the temperatures at Coral Cloud.
  1. Take a look at the steps the agent took and notice it selected the Check Weather action to fulfill the request.

    Agentforce Builder steps showing the prompt, selecting the Migration Default Topic then selecting the Check Weather action.
  1. Want the weather forecast for next week? Enter Check the weather for next week.
  2. Take a look at the steps again. The agent sent the date for each day of the week to build the response.

    Agentforce Builder steps showing multiple calls to the Check Weather action with different date Inputs.

Well done! You’ve taken a large step toward using all of the Apex functionality your org already has and delivering it up for AI agents to use. You’ve learned some best practices and how to set parameters to get the most out of your agents.

Resources

Condividi il tuo feedback su Trailhead dalla Guida di Salesforce.

Conoscere la tua esperienza su Trailhead è importante per noi. Ora puoi accedere al modulo per l'invio di feedback in qualsiasi momento dal sito della Guida di Salesforce.

Scopri di più Continua a condividere il tuo feedback