ChatGPT’s Blend of Tech and Humor: A New Approach to Salesforce Triggers

ChatGPT is a prototype artificial intelligence chatbot designed by OpenAI to understand natural human language and generate written text that closely resembles human writing.

I’ve played with ChatGPT for a little while to create a Salesforce trigger and will tell the results but, first, the routine it gave me when I’ve asked “Write a Seinfeld routine about Salesforce triggers.

Then I’ve asked ChatGPT: “Please write a Salesforce trigger that notifies case team members of any new Case Feed post.

Below was the response followed by ChatGPT’s very nice explanation: “This trigger will be executed whenever a new Case Feed post is created. It will first query the CaseTeamMember object to retrieve the case team members for the case associated with the post, and will store their user IDs in a set. It will then use these user IDs to query the User object and create a map of users. Finally, it will create an email message for each new Case Feed post, setting the recipients to the case team members, and will send the messages using the Messaging.sendEmail method.”

As you can see, the code is well-formatted and commented out, however it will NOT work properly:

  1. the trigger is missing the opening {, which ended up in the bottom of the code
  2. it runs a query on CaseTeamMember inside the first loop
  3. it uses “stream() .map(user -> user.Email) .collect(Collectors.toList())” which is not Apex and uses what seems like an undeclared variable “Collectors”.

Then I’ve tried again giving further details: “Please write a Salesforce trigger in Apex that notifies case team members of any new Case Feed post and avoid queries inside loops.”

The response:

It did respect the best practice of not placing a query inside a loop, but, otherwise, it had almost the same flaws:

  1. the trigger is missing the opening {, which ended up in the bottom of the code
  2. instead of collecting the case ids (parentId) it collected the post ids and added an unnecessary query on Case/CaseFeed
  3. again it used “stream() … .collect()” (non-Apex).

So I’ve made a third attempt with more details: “Please write a Salesforce Case Feed trigger in Apex that collects the parent case ids and uses it to retrieve the Case Team Member emails, then notifies each case team member about the Case Feed post. Avoid queries inside loops. Avoid stream() and collect() methods.” resulted in:

  1. it still collected the post ids instead of parent ids
  2. unnecessary nested queries
  3. missed some query optimizations

Fourth try: “Please write a Salesforce Case Feed trigger in Apex that collects the ParentIds and use them to retrieve the Case Team Member emails from the CaseTeamMember object, then notifies each case team member about the Case Feed post. Avoid queries inside loops. Avoid stream() and collect() methods. Avoid nested queries.”

It did figure out the part of querying the User object to collect the email addresses but the resulting code became more incomplete and looking worse than before. It included another query inside a loop. It was as if ChatGPT just started to give up! 🤷🏽♂️

I will try a more “baby-steps approach” later.

Then, since ChatGPT seems to shine at fiction writing, I’ve asked: “Write a dialogue that Lamar Davis would say in GTA 5 about Salesforce flows.”

Lamar: “Yo, have you seen those Salesforce flows? They’re like a bunch of little automation scripts, all connected together in one big flowy thing. You can use them to automate all kinds of processes, like creating records, updating fields, and sending notifications. It’s like a whole other level of hustling, right there in your Salesforce org.”

That does resemble Lamar, maybe after getting some Trailhead badges.

Then I’ve tried another Seinfeld routine: “Write a Seinfeld routine about Salesforce flows.”

Amusing! I would like to see what results others got!


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *