A support queue can look healthy until you open it and find hundreds of cases that customers already confirmed as resolved.
I have seen service teams spend hours every week reading “thank you, it works now” replies, updating fields, and closing straightforward cases manually.
An Agentforce Script AI Agent can handle this repetitive work, but it should not close every case blindly.
The right design lets the AI agent identify eligible cases, capture a clear closure reason, and run a controlled custom action that updates the Case record.
In this guide, I will show you how to build a Salesforce Agentforce Script AI agent custom action to close cases automatically with a Flow-based action.
What We Will Build
This is a practical how-to guide. We will use a Service Cloud example: a support team handles around 500 customer cases each month and wants the agent to close low-risk cases after the customer confirms that the issue is resolved.
The solution has three parts:
- An Agentforce Script AI Agent that understands the support request and decides whether closure makes sense.
- An autolaunched Flow, which is a Flow that runs in the background without a screen.
- A custom action that lets the agent invoke the Flow and update the Case safely.
The agent should close a case only when all of these conditions are true:
- The Case is currently open.
- The customer clearly confirms resolution.
- The Case does not have a high-priority or escalation flag.
- The agent has a valid Case ID and a closure reason.
This controlled approach protects your support process. It also gives agents more time for complex cases that need human judgment.
Why Use an Agentforce Script AI Agent Custom Action?
An Agentforce custom action gives an AI agent a defined business capability. Instead of asking the AI to describe what it would do, you let it run a specific Salesforce process with approved inputs and outputs.
For this use case, the action updates the Case object. A Case stores customer support issues in Service Cloud, including fields such as Status, Priority, Subject, Contact, and Case Owner.
You could build a record-triggered Flow that closes cases after a fixed number of days. However, an AI agent adds useful context. It can understand a message such as, “The password reset worked. You can close this ticket,” while ignoring a vague response such as, “I will test it tomorrow.”
Before building the action, make sure your agent has the right instructions, topics, and access. This guide on assigning custom actions to Agentforce agents explains how actions fit into an agent configuration.
Build the Flow Action to Close the Case in Salesforce
The safest pattern is to make the Flow responsible for the actual update. The AI agent passes values into the Flow, while the Flow validates those values before changing the Case.
Create an Autolaunched Flow
- Go to Setup and search for Flows.
- Click New Flow.
- Select Autolaunched Flow (No Trigger).
- Click Create.
An autolaunched Flow works well because Agentforce starts it as an action. It does not need a screen because the AI agent supplies the data.
Create these input and output variables:
| Variable API Name | Data Type | Availability | Purpose |
|---|---|---|---|
| varCaeNumber | Text | Input | Receives the Case Number |
| varMessage | Text | Outside | Receives the agent’s closure explanation |

For each variable, select Available for input. This setting makes the variable available when you configure the Agentforce action.
Get the Case Record
Add a Get Records element and configure it as follows:
- Object: Case
- Condition: Case Number Equals {!varCaseNumber}
- How Many Records to Store: Only the first record
- How to Store Record Data: Automatically store all fields

The Flow must retrieve the current Case before it decides whether to close it. This prevents the agent from updating a case that no longer exists or has already changed status.
Add the Safety Decision
Add a Decision element named Is Case Safe to Close?. Create an outcome named Eligible for Closure with this logic:
{!Get_Case.Status} Does Not Equal ClosedThis Decision element acts as a business safety gate. It checks the record’s current values instead of trusting the AI agent alone.

If your organization uses custom Case statuses, replace Closed with the exact closed status value from your support process. You can also add conditions for escalated cases, entitlement milestones, or specific record types.
Pro Tip: I have found that a “Do Not Auto Close” checkbox is one of the simplest safeguards you can add. Support managers can mark a sensitive case once, and the Flow will block the AI action without changing agent instructions.
Update the Case Fields Using Flows
From the Eligible for Closure outcome, add an Update Records element.
Configure it to update the Case record returned by Get Case:
- Status = Closed

Name the element Close Case and Save AI Reason.
The closure reason matters because it creates a clear audit trail. When a support manager reviews a closed case later, they can see why the agent made the decision.

If your org has validation rules that require a specific closed status, a Case Comment, or a resolution field, include those fields in this update. Learn how validation rules work in Salesforce before activating the Flow.
Agentforce Script AI Agent Custom Action to Close Cases
Now connect the Flow to your Agentforce Script AI Agent.
- Go to Setup and open Agentforce Assets.
- Select Action and click New Agent Action.
- Open the agent’s Actions section.

Use this description:
Closes an eligible support case only after the customer clearly confirms resolution.
Use this action only when a valid Case ID is available, the customer confirmed the solution,
and the case does not need human review. Provide a concise closure reason.
A precise action description improves the agent’s decision-making. It tells the agent when to use the action and, just as importantly, when not to use it.
For a fuller walkthrough of action setup, see how to create a custom action using Flow for Agentforce.
Add Clear AI Agent Instructions in Salesforce Agentforce
Your agent instructions should define a narrow, reliable closure policy. Add guidance like this to the relevant topic or agent behavior instructions:
Use the Close Eligible Support Case action only when the customer explicitly confirms
that the issue is resolved. Do not use the action for high-priority, escalated, unresolved,
or ambiguous cases. If the customer asks a follow-up question, keep the case open.
Include a short, factual closure reason.
Avoid broad instructions such as “close resolved cases automatically.” The word “resolved” can mean different things in a customer conversation. Specific criteria reduce incorrect actions.

If the agent should answer knowledge questions before it considers closure, connect the right support content through an Agentforce data library. This helps the agent give a useful response before deciding whether the case is complete.
Test the Case Closure Action
Do not activate this process directly in production. Test it in a sandbox first with a mix of eligible and ineligible cases.
Create the following test records:
| Test Case | Expected Result |
|---|---|
| Medium-priority case, customer says “The fix worked” | Agent closes the case |
| High-priority case, customer confirms resolution | Agent keeps the case open |
| Eligible case with Do Not Auto Close selected | Agent keeps the case open |
| Customer says “I will check later” | Agent keeps the case open |
| Already closed case | Agent does not update the record |

Review the Case History and the custom fields after each test. Also test the action using the same user profile or permission set that your agent will use.
A Salesforce sandbox gives you a safe place to test record updates, validation rules, and permissions before you expose the action to real customer conversations.
Proof of Concept
Whenever a user asks the question to agentforce agent to close the case, the agent will automatically close the case and update it in the Case object.

Things to Keep in Mind
- Use explicit confirmation: Close a case only when the customer clearly says the solution worked or asks to close the case.
- Respect Case priority: Keep high-priority, escalated, and sensitive cases outside automated closure unless your support leadership approves it.
- Check user access: Give the agent’s running user access to the Case object and required fields through the right profile or permission set.
- Keep Flow logic authoritative: Put the final safety checks in the Flow, not only in the agent instructions.
- Track every AI closure: Store a closure reason and an AI-closure checkbox so managers can audit outcomes and identify patterns.
- Test validation rules: A validation rule can block the update if your Flow does not populate mandatory closure fields.
Frequently Asked Questions
Can Agentforce close Salesforce cases automatically?
Yes. An Agentforce agent can run a custom Flow action that updates a Case status to Closed. You should add eligibility checks to the Flow so the agent closes only low-risk, clearly resolved cases.
Does an Agentforce custom action need Apex?
No. You can use an autolaunched Flow for many record-update actions, including closing Cases. Use Apex when your action needs complex logic, large-scale processing, or an external integration that Flow cannot handle cleanly.
How do I stop Agentforce from closing important cases?
Add Flow conditions for Priority, escalation status, record type, and a Do Not Auto Close checkbox. The Flow should reject the update whenever any of those conditions indicate that a human must review the case.
Can I capture why the AI agent closed a Case?
Yes. Create a long text field such as AI Closure Reason and pass the reason from the agent into the Flow. The Flow can save that reason during the Case update.
Why did my Agentforce Flow action not close the Case?
Check whether the Case passed every Decision condition in the Flow. Also verify the running user’s object permissions, field-level access, validation rules, and the active Flow version.
Should I use a record-triggered Flow instead?
Use a record-triggered Flow when a change to a fixed field or a time-based condition should close cases. Use an Agentforce action when the agent must interpret customer language and then request a controlled update.
Conclusion
An Agentforce Script AI Agent custom action gives your service team a structured way to close straightforward Cases without losing control of the support process.
Start with one narrow eligibility rule, test it thoroughly in a sandbox, and expand the logic only after your team trusts the results. I hope you found this article helpful.
You May Also Like
- Create and deploy an Agentforce service agent
- Automatically close cases using Salesforce Flow
- Set up Case escalation rules in Salesforce
- Create an open cases by owner report
- Transfer an Agentforce chat from AI to a human agent
I am Bijay Kumar, the founder of SalesforceFAQs.com. Having over 10 years of experience working in salesforce technologies for clients across the world (Canada, Australia, United States, United Kingdom, New Zealand, etc.). I am a certified salesforce administrator and expert with experience in developing salesforce applications and projects. My goal is to make it easy for people to learn and use salesforce technologies by providing simple and easy-to-understand solutions. Check out the complete profile on About us.