fork download
  1. public class GuestReviewProcessor {
  2.  
  3. @InvocableMethod(
  4. label='Process Guest Reviews',
  5. description='Creates a new Guest Review record from chat input using contact, experience, review, and rating.'
  6. )
  7. public static List<GuestReviewResponse> processReviews(List<GuestReviewRequest> requests) {
  8. List<GuestReviewResponse> responses = new List<GuestReviewResponse>();
  9. List<Guest_Review__c> reviewsToInsert = new List<Guest_Review__c>();
  10.  
  11. try {
  12. for (GuestReviewRequest request : requests) {
  13. Guest_Review__c review = new Guest_Review__c(
  14. Contact__c = request.contact.Id,
  15. Experience__c = request.experience.Id,
  16. Comments__c = request.review,
  17. Rating__c = request.rating
  18. );
  19. reviewsToInsert.add(review);
  20. }
  21.  
  22. if (!reviewsToInsert.isEmpty()) {
  23. insert reviewsToInsert;
  24. }
  25.  
  26. for (GuestReviewRequest request : requests) {
  27. GuestReviewResponse response = new GuestReviewResponse();
  28. response.message = 'Guest review submitted successfully for Contact ID: ' + request.contact.Id;
  29. responses.add(response);
  30. }
  31.  
  32. } catch (Exception e) {
  33. for (GuestReviewRequest request : requests) {
  34. GuestReviewResponse response = new GuestReviewResponse();
  35. response.message = 'Failed to submit guest review for Contact ID: ' + request.contact.Id + '. Error: ' + e.getMessage();
  36. responses.add(response);
  37. }
  38. }
  39.  
  40. return responses;
  41. }
  42.  
  43. // Wrapper class for input (do not mark static)
  44. public class GuestReviewRequest {
  45. @InvocableVariable(
  46. required=true,
  47. label='Contact',
  48. description='The Contact record associated with the guest submitting the review.'
  49. )
  50. public Contact contact;
  51.  
  52. @InvocableVariable(
  53. required=true,
  54. label='Experience',
  55. description='The Experience record that the guest is providing feedback on.'
  56. )
  57. public Experience__c experience;
  58.  
  59. @InvocableVariable(
  60. required=true,
  61. label='Review',
  62. description='The written feedback or comments from the guest.'
  63. )
  64. public String review;
  65.  
  66. @InvocableVariable(
  67. required=true,
  68. label='Rating',
  69. description='The rating (e.g., 1-5) given by the guest for their experience.'
  70. )
  71. public String rating;
  72. }
  73.  
  74. // Wrapper class for output (do not mark static)
  75. public class GuestReviewResponse {
  76. @InvocableVariable(
  77. label='Status',
  78. description='A message indicating whether the guest review was processed successfully or failed.'
  79. )
  80. public String message;
  81. }
  82. }
  83.  
Success #stdin #stdout #stderr 0.01s 10564KB
stdin
Standard input is empty
stdout
Object: UndefinedObject error: did not understand #GuestReviewProcessor
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
UndefinedObject class(Object)>>doesNotUnderstand: #GuestReviewProcessor (SysExcept.st:1448)
UndefinedObject>>executeStatements (prog:1)
Object: nil error: did not understand #associationAt:ifAbsent:
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
UndefinedObject(Object)>>doesNotUnderstand: #associationAt:ifAbsent: (SysExcept.st:1448)
DeferredVariableBinding>>resolvePathFrom: (DeferBinding.st:115)
DeferredVariableBinding>>value (DeferBinding.st:69)
UndefinedObject>>executeStatements (prog:22)
stderr
./prog:3: parse error, expected '}'
./prog:22: expected expression