Write your first Salesforce validation rule using ChatGPT

Amit Arora
GPTcommands
3 min readDec 16, 2022

--

Want to advance your ChatGPT skills ✍️ join others and learn how you can master ChatGPT and take your prompt skills to the next level 🚀

>> Click here to learn more <<

What is ChatGPT?

ChatGPT is a variant of the GPT (Generative Pre-trained Transformer) language model that is specifically designed for chatbot development. It is trained on a large dataset of human-generated text and is able to generate responses that are similar to those of a human. ChatGPT can be used to create chatbots that can carry on conversations with users in a natural, human-like manner.

There are a few key differences between ChatGPT and the original GPT model. For example, ChatGPT is trained to generate text in the form of chat messages, while the original GPT model is trained to generate text in the form of articles or stories. Additionally, ChatGPT is designed to handle more diverse input and output, making it more suitable for use in chatbot development.

Overall, ChatGPT is a powerful tool for creating chatbots that can engage users in natural conversations. It can be used to build chatbots for a wide range of applications, including customer service, e-commerce, and entertainment.

How to get ChatGPT to write a simple Salesforce validation rule?

Use Case: Let’s try a validation rule where-in I would like users to get an error message if they change the Opportunity stage from the Discovery stage to the Costing stage without filling in the ACV__c field and the CloseDate field.

Command: Write me a salesforce validation rule where-in I would like users to get an error message if they change the Opportunity stage from the Discovery stage to the Costing stage without filling in the ACV__c field and the CloseDate field.

Response from ChatGPT 🤯

Here is a Salesforce validation rule that will prevent users from moving an Opportunity from the Discovery stage to the Costing stage without filling in the ACV__c field and the CloseDate field:

AND(
ISCHANGED(StageName),
StageName = “Costing”,
OR(
ISBLANK(ACV__c),
ISBLANK(CloseDate)
)
)

Response from ChatGPT

This validation rule checks if the StageName field has been changed and if the new value is “Costing.” If these conditions are met, it checks whether the ACV__c field or the CloseDate field is blank. If either of these fields is blank, the validation rule will return an error and prevent the Opportunity from being saved.

You can customize the error message displayed to the user by editing the “Error Message” field of the validation rule.

While ChatGPT was able to understand my command and provide me with a proper validation rule, it seems to have forgotten to add the PRIORVALUE function so the previous stage could’ve been recognized.

The correct formula would look something like this:

AND(
PRIORVALUE(StageName) = "Discovery",
ISCHANGED(StageName),
StageName = "Costing",
OR(
ISBLANK(ACV__c),
ISBLANK(CloseDate)
)

After altering the command, ChatGPT was able to complete my validation rule. But I still had to google first to make sure that the validation rule was incorrect.

My prompt to correct the validation rule 👇

The validation rule doesn’t look for previous stage being Discovery. Can you try again?

Updated command with a complete validation rule

What’s your favorite command for ChatGPT? Get your free ChatGPT account at https://chat.openai.com/chat

--

--

Amit Arora
GPTcommands

6X Salesforce ☁️ Certified | Certified Sales Cloud Consultant | Service Cloud Consultant | Community Cloud Consultant | Platform App Builder