Jumpstart Your Formulas with AI.

Jumpstart Your Formulas with AI

By

AI + Salesforce formulas

Formulas are a powerful tool within the Salesforce Platform, and with the advent of artificial intelligence (AI), admins have a robust new tool in their toolkit to create and edit them. Whether it’s jumping the line to start on a complicated formula or trying to figure out what’s wrong with that formula, AI provides the means to get the task done—and fast. Let’s break down how you can have a conversation with AI to jump-start creating and updating formulas.

Context is important

It’s good to remember that conversational generative AIs like ChatGPT and Bard are best run with as much context as possible. For instance, when creating formulas for Salesforce, refer to them as Salesforce formulas. There are a lot of different kinds of formulas out there and it’s best to be as specific as possible when starting your conversation. Once you’ve said you want formulas for Salesforce, the AI will likely remember that within the same session and conversation and, hence, it’ll be less important moving forward. But it’s always best to start with the right foot forward.

Keep it conversational

You can always modify what the AI outputs for you based on your conversation. So, even asking the prompt:

write a formula field for Salesforce that escalates two days after creation

You might get the formula:

IF(NOW() - CreatedDate > 2, "Escalated", "Not Escalated")

However, this kind of field might be better served as a checkbox so that it can be treated like a simple boolean. So now, I can ask:

can you rewrite that to be a checkbox

Note that I don’t need to remind it what “that” means. It knows based on the context what you’re talking about and will respond with:

IF(NOW() - CreatedDate > 2, true, false)

And now, you can edit that formula easily with prompts like make that 4 days”. Imagine being able to do this not just in the sense of being a lone admin creating a few custom formula fields, but working in coordination with other people. It’s very easy to update the responses you get based on new data if the business requirements change while planning.

Make it complicated

One of the more powerful things you can do with AI is skip ahead and get a complicated formula based on business requirements. For instance, let’s say you’re given the following requirements.

  • If the StageName field is “Closed Won”, it assigns a score of 10; otherwise, it adds 0.
  • If the LastModifiedDate is blank and the Type is either “New Business” or “Existing Business”, it assigns a score of 5; otherwise, it adds 0.
  • If the Probability is 50% or greater and the Amount is greater than or equal to 100,000, it assigns a score of 8; otherwise, it adds 0.
  • If the Amount is greater than or equal to 50,000 and the LeadSource is not blank, it assigns a score of 6; otherwise, it adds 0.

Again, context is important, and this allows you to focus on the actual requirements being asked of the platform. You and your business partners can tweak the requirements themselves and then copy and paste them into the AI to get:

(
  IF(ISPICKVAL(StageName, "Closed Won"), 10, 0) +
    IF(
      AND(
         ISBLANK(LastModifiedDate),
         OR(
            ISPICKVAL(Type, "New Business"),
            ISPICKVAL(Type, "Existing Business")
          )
      ),
    5,
    0
    ) +
  IF(
    AND(
        Probability >= 50,
        Amount >= 100000
    ),
   8,
   0
   ) +
   IF(
     AND(
        Amount >= 50000,
        ISBLANK(LeadSource)
     ),
    6,
    0
   )
)

I should note that, along the way, AIs like ChatGPT and Bard will also offer up friendly context, as a standard part of their response, with things like:

The final lead score is the sum of the weighted scores from each criterion.
Please note that this is a simplified example, and you can adjust the weights, criteria, and formulas based on your specific business requirements.

But wait… that’s wrong?

Indeed. If you put that formula into the Opportunity object, you’ll get this from our friendly formula editor:

Error: Field LeadSource is a picklist field. Picklist fields are only supported in certain functions.

That’s why it’s important to remember that these AIs are fallible. In this case, it’s replicating a very common error which it probably found in its dataset when trying to form this response. The data in the foundational models isn’t scrubbed for accuracy; rather, accuracy is something created by the overall weight of accurate data. In other words, since most of the data is accurate, most of the answers will be accurate.

But the key word here is most. This is why we always need to keep a human in the loop to review and potentially fix what the AI gives us.

This also gives an example of how to correct a formula using AI, whether a human or AI created it in the first place. Just ask the AI to do it. Again, this is a conversation and you can just point out that there’s an error.

That formula gives the following error:
Field LeadSource is a picklist field. Picklist fields are only supported in certain functions
Can you fix that?

And we get:

Apologies for the oversight. You're right, the `LeadSource` field is a picklist field, and it cannot be directly used in the formula as written. To handle picklist fields in formulas, you can use the `ISPICKVAL` function. Here's the updated formula that addresses the issue:

(
  IF(ISPICKVAL(StageName, "Closed Won"), 10, 0) +
  IF(
    AND(
      ISBLANK(LastModifiedDate),
      OR(
        ISPICKVAL(Type, "New Business"),
        ISPICKVAL(Type, "Existing Business")
      )
    ),
    5,
    0
  ) +
  IF(
    AND(
      Probability >= 50,
      Amount >= 100000
    ),
    8,
    0
  ) +
  IF(
    AND(
      Amount >= 50000,
      NOT(ISPICKVAL(LeadSource, ""))
    ),
    6,
    0
  )
)

In this updated formula, the `ISPICKVAL` function is used to compare the `LeadSource` field with an empty string `""` to check if it is not blank. If it is not blank, it assigns a score of 6; otherwise, it adds 0.

Please note that the empty string `""` assumes that the picklist field does not have a specific value designated for blanks. If your picklist field has a specific value for blanks, you can replace `""` with the appropriate value in the formula.

With this modification, the formula should now work without any issues related to using a picklist field.

And the formula editor agrees.

Be careful with the AI

Here at Salesforce, we’re very excited about how AI can help make our lives more productive. But it’s good to be aware of what you should and shouldn’t do with these tools. Here are some of our base guidelines.

  • Do not use the name, image, or likeness of anyone as an input or prompt.
  • Do not use content produced by someone else as an input or prompt.
  • Do not input any Salesforce proprietary, personal, or confidential information into third-party models.
  • Do not use any AI tool without checking the terms and conditions.
  • Do not rely on information from an AI tool without double-checking accuracy.
  • Do thoroughly review AI output before use and add your own modifications.
  • Do disclose the use of AI when necessary.
  • Do keep records of inputs and modifications, if possible.

Where to learn more

See our previous articles on AI Prompt Writing for Salesforce Professionals and Be an AI-Minded Salesforce Admin.

And coming soon there will be even more ways to jumpstart your formulas with AI! With Einstein for Formulas, you can understand, fix and create formulas faster than ever before! Watch the Spring ’24 Admin Preview: Release Readiness Live to see a sneak peek at this new feature coming soon.

Governance strategies for your first AI project

AI and Agentforce: Governance Strategies for Your First AI Project

There is a lot of excitement around artificial intelligence (AI) right now. New uses and new models are changing the way we think about how AI can support and improve the ways we work.  At Dreamforce ’24 one of the big announcements was Agentforce, a powerful companion to help Salesforce users resolve cases, answer questions, […]

READ MORE
Prepare for the AI Specialist Exam and Agentforce

Prepare for the Salesforce AI Specialist Exam and Agentforce

As Salesforce Admins, we have clear core responsibilities that define our day-to-day roles. We manage users, data, and product, provide actionable analytics, and oversee security. But we’re currently in the third wave of the artificial intelligence (AI) revolution: contextual and generative AI, characterized by prompt-based generative AI, real-time AI applications, and autonomous agents.  This means […]

READ MORE
Introduction to Agentforce for Salesforce Admins

Introduction to Agentforce for Salesforce Admins

What is Agentforce? We are living in the artificial intelligence (AI) era, currently in the third wave of the AI revolution focused on contextual and generative AI and characterized by prompt-based generative AI, real-time AI applications, and autonomous agents. Agentforce is the suite of both assistive and autonomous agents built on the Salesforce platform. Agents […]

READ MORE