Skip to main content
Stream TDX live on Salesforce+. Join virtual sessions and hands-on trainings to experience the future of software and learn how to build it.

Enforce Business Rules with Variables and Action Filters

Learning Objectives

After completing this unit, you’ll be able to:

  • Enforce business rules by filtering actions from the LLM.
  • Set a variable's default value so that conditional checks work correctly.

Now, let's give some tangible rewards to your loyal customers. You want your agent to issue a $500 resort credit to your Platinum customers, and a $250 resort credit to your Gold customers. To do that, you create an IssueResortCredit action, then add specific instructions for each loyalty level.

Note

To align with industry standards, Agentforce topics are now called subagents. Currently, this module uses the legacy term topic.

Create the IssueResortCredit Action

Create an action that issues resort credit to customers, given a contact ID and a credit amount.

  1. In the Explorer panel, in Canvas view, select the plus icon next to the Experience Management topic.
  2. Select +New Action.
  3. Name the action IssueResortCredit.
  4. Add the description: Issue resort credit using the ContactId and provided amount.
  5. Click Create and Open.
  6. For Reference Action Type, select Flow.
  7. For Reference Action, select Issue Resort Credit.
  8. Scroll down to the Inputs and Outputs sections, and add checkmarks to:
    • amount input: Require Input to execute action
    • contactId input: Require Input to execute action
    • creditID output: Show in conversation
  1. Click Save.

Grant the Agent User Permissions to Credit__c

Next, give your agent user read and write permissions to the Credit__c object, so your agent can issue resort credit to your loyal customers.

  1. From Setup, in the Quick Find box, search for and select Users.
  2. Click the EinsteinServiceAgent User username.
  3. At the top of the page, click Permission Set Assignments.
  4. Select Service Agent Permissions, then under Apps, select Object Settings.
  5. Scroll down, select Credits (the Credit__c object ), and click Edit.
  6. Enable Read and Create object permissions, then grant edit access to Amount and Contact fields.
  7. Click Save.

Credit__c object with all object permissions enabled and Read and Edit access granted to Amount and Contact fields.

Update the Agent to Issue Loyalty-Specific Credit Amounts

  1. In Agentforce Builder, return to your CC Service Agent.
  2. In the Explorer panel, in Canvas view, click the Experience Management topic.
  3. In the topic's reasoning instructions, expand the arrow by If LifetimeValue >= 50000.
  4. Click at the end of the sentence Thank the customer for being a Platinum member!, type a space, and then type If.
  5. Type the @ symbol, select This Agent's Actions, then select IssueResortCredit.
  6. Add the remaining instructions is available, issue the customer a $500 resort credit. Tell them about the resort credit!
  7. Repeat the above steps to issue a $250 resort credit to Gold members if their lifetime value is between $50,000 and $25,000.

Conditional statement updated to grant resort credit

  1. Click Save.

Test Your Resort Credit Action

Now, let's see your agent give Sofia the resort credit she's earned!

  1. In Preview, you might be prompted to reset the simulator. Accept it, then enter this prompt: Can you let me know more about the full moon beach party experience?
  2. When asked for email and membership number, enter: I am sofiarodriguez@example.com and my membership number is 10008155.

The agent replies with a message similar to "Thank you for being a Platinum member, Sofia! You have received a $500 resort credit as a special benefit."

To verify that the resort credit is issued, let's look at Sofia's contact record.

  1. Click the App Launcher, then search for and select Contacts.
  2. Search for, then double-click the Sofia Rodriguez contact to open.
  3. In Sofia's contact record, click the Related tab.
  4. Scroll down to Credits and verify that her $500 credit was added.

Resort Credit issued

You've ensured that your agent issues the correct value credit for the customer's loyalty level. Now, let's use action filtering to make sure your agent follows business rules when issuing resort credits.

Add Action Filtering to Enforce Business Rules

Your conditional logic ensures that your agent gives specific instructions to the LLM, based on the customer's loyalty status. However, right now, the IssueResortCredit action is always available to the LLM—nothing is stopping Sophia from asking for 5 more credits! With other agents, your only option to control the number of credits issued is to add strict prompt instructions. Because prompt instructions aren't deterministic, this approach leaves other agents vulnerable to LLM mistakes (or extra-convincing customers). But with Agentforce, you can use action filtering to deterministically enforce your business rules.

Let's add filtering to hide the action from the LLM if your business conditions aren't met. If the customer's lifetime value is below $25,000, or if the user has already received a resort credit during this session, the LLM won't even see the action—making it impossible to accidentally issue credits to ineligible customers.

Create the isCreditEligible Variable

You use this variable to track whether a customer is eligible for a credit.

  1. In the Explorer panel, click Variables.
  2. In the upper right, click New, then select Create Custom Variable.
  3. Set these properties:
    • Name and API Name: isCreditIssued
    • Data Type: Boolean
    • Description: Whether the customer has already been issued a resort credit this session.
    • Default value: False
  4. Click Create.

You set the default value to False even though Agentforce automatically sets boolean variables to False if their default value is unspecified. By clearly specifying a default value, you're making it easier for your coworkers to understand conditional logic if they ever need to update your agent.

isCreditIssuedvariable defined

Update the IssueResortCredit Action to Set isCreditIssued

In your script, you set the isCreditIssued variable to True once the first credit is issued, preventing the agent from issuing more credit during the current session.

Note

The isCreditIssued variable resets to False every session, meaning the agent can potentially issue a credit in every new customer session. In a production agent, you'd want to use a more restrictive method, such as creating a flow to check whether the customer has already been issued a credit for the current resort stay.

  1. In Canvas view, select the Experience Management topic and scroll down to Actions Available for Reasoning.
  2. Expand the IssueResortCredit action, click next to the IssueResortCredit label, then click Add filter.

Add filter popup

  1. Next to Available when: select the variable isCreditIssued, then create the filter Available When isCreditIssued == False.
  2. Click to the right of the False block so the Add to block widget appears, then click And.
  3. Create the filter And LifetimeValue >= 25000.
  4. Click after the text creditID so that the widget Add to block: Follow-up action appears.
  5. Click Follow-up action then click Set a variable.
  6. Select isCreditIssued, then select True.
  7. Click Save.

In Canvas, your IssueResortCredit reasoning action looks like this.

Issue resort credit action with filter

Now the LLM can only see the IssueResortCredit action if the customer's lifetime value is $25,000 or greater, and if the customer hasn't been issued a credit. Even if a customer tries to convince the agent they deserve a credit, the agent physically cannot access the action! Give it a try and see how the agent responds.

Conclusion

You've gotten your first taste of Agentforce determinism and Agent Script. You used variables, conditional instructions, and action filters to define separate workflows for Platinum, Gold, and regular customers. With each conversation turn, Agentforce follows your defined logic to create a tailored prompt and identify eligible actions, then sends only the appropriate content to the LLM. By defining this loyalty-tier specific logic, you've preserved your agent's reasoning and conversational abilities, while allowing the agent to reward your loyal customers within strictly defined guardrails.

Resources

Quiz Scenario

Consider this scenario for the first quiz question. Ago_to_escalation action in the topic_selector topic is filtered with this available when clause:

 available when @variables.customerVerified == True and @variables.officeOpen == True
在 Salesforce 帮助中分享 Trailhead 反馈

我们很想听听您使用 Trailhead 的经验——您现在可以随时从 Salesforce 帮助网站访问新的反馈表单。

了解更多 继续分享反馈