Superbadge: Apex for Agentforce
Implement custom solutions using Apex agent actions in Agentforce.
Superbadge: Apex for Agentforce
Ce que vous devez accomplir pour gagner ce superbadge
- Create an invocable Apex class to call an existing functionality.
- Invoke a prompt template from an Apex class.
- Create an Apex action for an Agent.
Concepts testés avec ce Superbadge
- Agent Customization with Apex
Prework and Notes
Sign Up for a Developer Edition Org with Special Configuration
To complete this superbadge, you need a special Developer Edition org that contains special configuration and sample data. Note that this Developer Edition org is designed to work with the challenges in this superbadge.
-
Sign up for a free Developer Edition org with special configuration.
Fill out the form. For Email address, enter an active email address.
- After you fill out the form, click Sign me up.
After you receive the activation email (this might take a few minutes), open it and click Verify Account.
Complete your registration by setting your password and the challenge question.
Tip: Save your username, password, and login URL in a secure place—such as a password manager—for easy access later.
You are now logged in to your superbadge Developer Edition org.
Now, connect your new Developer Edition org to Trailhead.
Make sure you’re logged in to your Trailhead account.
In the Challenge section at the bottom of this page, select Connect Org from the picklist.
On the login screen, enter the username and password for the Developer Edition org you just set up.
On the Allow Access? page, click Allow.
On the Want to connect this org for hands-on challenges? page, click Yes! Save it.
You are redirected back to the Challenge page and ready to use your new Developer Edition org to earn this superbadge.
Now that you have a Salesforce org with special configuration for this superbadge, you’re good to go.
Use Case
Coral Cloud Resorts is a vacation destination with something for everyone. The resort works hard to provide great experiences for guests, who choose from hundreds of activities and adventures. In this superbadge, you’ll use Apex and Agentforce to help the team at Coral Cloud Resorts provide excellent service, strengthen customer relationships, and gain repeat business for the resort. Your work focuses on two areas: guest experience reviews and campaigns.
Guest Experience ReviewsGuest reviews are a key element of Coral Cloud’s success. On the Coral Cloud website, each experience is listed with a brief description, price, an overall rating, and snippets of individual guest reviews. Guests provide a review in their own words and give the experience a numeric rating from 1–10, with 10 being outstanding. These reviews then guide future decisions for returning customers. Guests can choose to book the Tropical Snorkel Adventure, Sunrise Mountain Yoga, or the Kids’ Marine Discovery, just to name a few examples. They partly base their booking decisions on reviews and ratings.
Guest CampaignsManagement at Coral Cloud uses campaigns to stay in touch with customers between stays. Each year, guests can qualify for different campaigns based on their interests and experiences.
As a Salesforce developer, you’ve been asked to help Coral Cloud automate its process for capturing reviews and adding guests to campaigns. You’ll set up some new functionality in the Coral Cloud CRM by working with Agentforce and Apex customizations.
Get Ready for the Superbadge: Apex for Agentforce
Configure Agentforce in Your Org
You’ll need to use Agentforce in your org to complete objectives. Follow these steps to set up the agent in your connected developer edition org.
- Enable Einstein and Agentforce.
- Open the Coral Cloud Experience Agent in Agentforce Builder.
- Create a new topic named
Customer Experience Reviewswith the following information.Note: Click Next to advance past the optional “What do you want this topic to do?” modal, then add the field values in the next modal screen.
- Add the following Flow Agent Actions.
- Lookup Contact by Email: This action queries the contact record based on an email address.
- Get Most Recent Booking by Contact: This action queries the most recent booking record before today.
- Lookup Experience: This action queries the experience record based on an experience name.
- Set up the agent to capture the contact’s email.
- Select Context in the Agent Builder tool palette.
- Select Messaging Session under Context Variables.
- Click Edit Included Fields.
- Select the Email__c field.
- Click Save Included Fields to save this setting.
| Field | Value |
|---|---|
| Classification Description | This topic handles guest reviews about their experience at Coral Cloud Resorts. It identifies the specific experience, processes customer feedback, and records their review in the Coral Cloud Resorts org. |
| Scope | Your sole job is to gather and process guest reviews about their experiences at Coral Cloud Resorts to ensure feedback is accurately recorded and categorized. |
| 1st Instruction |
Always begin by checking that the Email__c field on the MessagingSession record is available with the session. If the Email__c field is available, then use this value to get the Contact record. If the Email__c field value is not known, always ask the customer for their email address and get their Contact record before creating the Guest Reviews record from the customer.
|
| 2nd Instruction |
Get the Contact record by using the Lookup Contact by Email action. Then get the most recent Booking information by using the Get Most Recent Booking by Contact action.
|
| 3rd Instruction |
There's an Experience Name field in the Booking record retrieved from the Get Most Recent Booking by Contact action. Confirm with the customer that the review they want to submit is for the experience related to this booking.
|
| 4th Instruction |
If the experience name is not what the customer intends to provide a review for, ask the user for their experience name. Check that the Booking record with this experience name exists for the customer, then confirm the experience name with the customer.
|
| 5th Instruction |
Use the Experience Name field on the Booking record to call the Lookup Experience action to get the Experience__c record.
|
| 6th Instruction |
Prompt the user to provide their review and a numeric rating on a scale of 1-10, with 10 being the most favorable rating. If the user submits a decimal rating, round it to the nearest whole number. Once both the review and the rating are received, invoke the Process_Guest_Reviews action with the collected details.
|
Now that you've configured Agentforce in your org and prepared the Coral Cloud Experience Agent, move on to the next challenge.
Create an Invocable Apex Class to Call an Existing Functionality
In this challenge, you help the Coral Cloud team automate the way they gather, process, and store guest experience reviews in the Coral Cloud org. While gathering requirements, you learn that the Coral Cloud org already has some Apex-based campaign functionality, and Coral Cloud plans to connect it to Agentforce soon. You determine that using Apex is the best way to implement an agent chat option to submit experience reviews, since you know the solution will also be extended to campaigns soon.
Process Guest Reviews
Coral Cloud Resorts has already deployed a Service Agent on its site. Your first task is to ensure that the Coral Cloud Experience Agent captures the correct information whenever a guest uses the agent chat option to submit an experience review. You have already added a topic called Customer Experience Reviews for this purpose.
To customize the Agentforce action for the Coral Cloud team, use an existing Apex class named GuestReviewProcessor in the Coral Cloud org. Using invocable variables, collect key information from a guest review. Then create an invocable method to process and properly handle the review’s details.
Build out an input wrapper class named GuestReviewRequest in the GuestReviewProcessor class and require Contact, Experience, Review, and Rating. The input wrapper class defines the input variables of these types: Contact contact, Experience__c experience, String review, and String rating. All variables should have the required parameter set to true. Add an appropriate description parameter for each of the variables. We won’t check the precise text used for the description, only that it exists.
Build out an output wrapper class named GuestReviewResponse in the GuestReviewProcessor class that includes a message that communicates the result of the action. Use the Output variable String message and define the label parameter as status. Include the description parameter for the message variable.
Build an invocable method called processReviews with the label parameter Process Guest Reviews and an appropriate description. Make use of the input wrapper class GuestReviewRequest to capture the information from the chat to create the guest review record with the captured contact (Contact__c), experience (Experience__c), review (Comments__c), and rating (Rating__c) details. The processReviews method uses the output wrapper class GuestReviewResponse to display the message if the review was successfully processed. Ensure that you use best practice for exception handling. If the review encounters a failure, make sure the output variable message communicates to the user that there’s been a problem.
Finally, create the guest review record with the captured contact, experience, review, and rating details.
When you create the guest review record, you may choose to tie it to the existing functionality around campaigns in CampaignMemberController class, but we won't check this.
Invoke a Prompt Template from an Apex Class
Reviews are a valuable resource for the resort. Guests rely on an experience review and its rating to decide whether to book it for their next vacation stay. Let’s explore the data gathered in reviews and ways to put it to work.
Enhance the Review Process
In the current review process, guests are asked to provide a review in their own words and give the experience a numeric rating from 1–10, with 10 being outstanding. Some guests have indicated that they’d like more details about an experience than just an overall rating. Since Coral Cloud is always looking to improve customer satisfaction, the team takes a closer look. What are some additional details about an experience that guests would find useful?
Working with the Coral Cloud team, you identify three more detailed attributes to supplement the overall rating. Value is mentioned in a lot of reviews where guests say things like, “Definitely worth the price!” Another important attribute is whether the experience lived up to guest expectations. Call that attribute Accuracy. And lastly, guests often comment about how well the resort staff prepared them to enjoy their experience. You name the last attribute Communication. Value, Accuracy, and Communication are the custom rating fields on the experience object.
There’s a prompt template named Experience Guest Reviews Evaluator. This existing prompt template evaluates all the guest review records related to an experience, calculates a numeric 1-10 rating, and responds in a JSON format that rates each attribute.
- Value: The experience delivered value for the price.
- Accuracy: The description accurately represents the experience.
- Communication: Resort staff clearly communicated details about the experience.
There’s a skeleton code in the class GuestReviewRatingCalculator. This class has a method called generateRatingParams, which takes the experience record id as a parameter. In this method, the inputParams map should be set with the prompt template input. Replace the placeholder text (REPLACE_WITH_PROMPT_TEMPLATE_INPUT) in the skeleton code with the prompt template input.
The generationsOutput should call the service generateMessagesForPromptTemplate to generate a response by specifying both the prompt template API Name Experience_Guest_Reviews_Evaluator and the input parameters set up in the invocation parameters section. Finally, set the response with the generations property from the generationsOutput variable.
The remainder of the code deserializes the response and updates the experience record with the evaluated rating.
Good work. To review, within the Apex class GuestReviewRatingCalculator, you used a method called generateRatingParams. Your code invoked the prompt template to generate a response. That response is deserialized and used to update the experience record with the additional attributes for Value, Accuracy, and Communication. If you would like to check that the additional attributes were added to an experience record, you can use the Beach Bootcamp Challenge experience record id to invoke the generateRatingParams method in Developer Console.
Configure an Apex Action for an Agent
For their final request, the team at Coral Cloud asks you to implement a solution where guest reviews can be processed smoothly by the Coral Cloud Experience Agent. You need to enable the correct permissions, create the necessary automation, and link the action to the appropriate agent topic.
The EinsteinServiceAgent User already has some permissions, granted by the Guest Reviews and Campaign permission set. Update that permission set to make sure it also grants permission to use the GuestReviewProcessor Apex class. Create a new Apex agent action for the Coral Cloud Experience Agent named Process Guest Reviews. Make sure the Agent Action API Name is Process_Guest_Reviews. Assign this agent action to the Customer Experience Reviews topic.
Note: We're not checking the loading text and input/output configurations of the agent actions beyond what’s outlined above.
Sum It Up
If you were reading closely, you’ll have noticed that this use case referred to the Coral Cloud site, but the superbadge challenges didn’t require you to work in Experience Cloud. If you’d like to flex your skills further, you can test your agent setup in Experience Cloud. To do this, there are some additional setup steps necessary in your developer org. Refer to the Apex for Agentforce Superbadge: Trailhead Challenge Help article for more information.
Whether you’re a Salesforce developer or an advanced administrator, completing this superbadge showcases your ability to combine Apex with Agentforce to implement custom solutions for an organization. Using Apex customizations, you extended Agentforce capabilities to create new automations and workflows. You demonstrated this by helping Coral Cloud streamline its guest review processing and campaign management. You also set up automated workflows to collect reviews, process ratings, and integrate guests into campaigns for the team at Coral Cloud. Congratulations on completing the Apex for Agentforce technical skills assessment!



