本文是《Superbadge: Apex for Agentforce | Superbadge 面向 Agentforce 的 Apex》的练习操作步骤。阅读原文请见:Superbadge: Apex for Agentforce | Superbadge 面向 Agentforce 的 Apex。
1. Create an Invocable Apex Class
- In the existing GuestReviewProcessor Apex class, build an input wrapper class
GuestReviewRequestwith these required variables (allrequired = true, each with a description):- Contact
contact - Experience__c
experience - String
review - String
rating
- Contact
- Build an output wrapper class
GuestReviewResponsewith an output Stringmessage(labelstatus, with a description). - Build an invocable method
processReviews(labelProcess Guest Reviews, with a description) that:- Takes
GuestReviewRequestas input. - Creates a guest review record with the captured
Contact__c,Experience__c,Comments__c, andRating__c. - Uses
GuestReviewResponseto return a success message, or an error message on failure (best-practice exception handling).
- Takes
- (Optional) Tie the record to the CampaignMemberController campaign functionality.
2. Invoke a Prompt Template From an Apex Class
- In GuestReviewRatingCalculator, in the
generateRatingParamsmethod, replaceREPLACE_WITH_PROMPT_TEMPLATE_INPUTwith the prompt template input. - Set
generationsOutputto callgenerateMessagesForPromptTemplatewith the prompt template API nameExperience_Guest_Reviews_Evaluatorand the input parameters. - Set the response using the
generationsproperty fromgenerationsOutput. - The rest of the code deserializes the response and updates the experience record with Value, Accuracy, and Communication.
- (Optional) Test by invoking
generateRatingParamswith the Beach Bootcamp Challenge experience record ID in Developer Console.
3. Configure an Apex Action for an Agent
- Update the Guest Reviews and Campaign permission set to grant the EinsteinServiceAgent User permission to use the GuestReviewProcessor Apex class.
- Create a new Apex agent action for the Coral Cloud Experience Agent named
Process Guest Reviews(API nameProcess_Guest_Reviews). - Assign this agent action to the Customer Experience Reviews topic.