Agentforce Rules
Rules let you establish consistent coding standards, architectural patterns, and project-specific preferences that Agentforce follows across all development sessions. Unlike one-time prompts, rules persistently shape how Agentforce works, keeping outputs aligned with your team’s practices.
Agentforce rules honor the agents.md standard, providing a portable, tooling-agnostic way to define persistent AI guidance that travels with your code.
Agentforce also includes a set of out-of-the-box (OOTB) rules to help you get started with Salesforce development best practices. To view them, click Rules & Workflows (⚖️ icon). You can turn global rules on or off, with a4d-general-rules-no-edit.md, a4d-apex-rules-no-edit.md and a4d-lwc-rules-no-edit.md enabled by default.
You can edit these rules if needed, but keep in mind that changes to OOTB rules are overwritten when the extension is updated.
Key Benefits
- Enforce coding patterns and architectural decisions.
- Maintain Salesforce org structure and business requirements.
- Share practices across development teams.
- Ensure adherence to security, testing, and documentation standards.
Rule Types
- Global Rules: Apply to all Agentforce sessions across projects.
- Workspace Rules: Specific to individual Salesforce projects or orgs.
Quickly create rules through Agentforce's built-in interface:
- Access Rules Tab: Click Rules & Workflows (⚖️ icon) in the Agentforce chat interface.
- Select Rule Type: Select either Global Rule or Workspace Rule.
- Create a Rule: Click
+to create a rule.
You can also have Agentforce create a rule for you by using the /newrule slash command in the chat.
Workspace rules are stored in your project's .a4drules folder. The location of global rules varies based on your operating system.
Rules are loaded when Agentforce starts a task. Here’s what happens:
Agentforce checks for rules in this sequence:
.a4drules/ folder (all .md files inside)- Single
.a4drulesfile agents.mdfile
- Workspace rules override global rules when both define the same guidance.
- When using a
.a4drules/folder, all Markdown files are combined into one ruleset. Numeric prefixes (like 01-, 02-) control the order.
Agentforce provides a convenient popover interface that allows you to:
- See which global and workspace rules are currently active.
- Turn specific rules on or off with a single click.
- Quickly create or delete rules.
Use this simple rules format to create your custom rules:
Here are some sample customization rules that you can use as guidelines to create your own rules. Applying these rules ensures uniform code quality, easier maintenance, and improved collaboration. Agentforce applies these best practices automatically whenever it generates code, reducing the need for manual reviews and refactoring.
This example Apex best practices rule defines a comprehensive set of coding conventions and best practices for all Apex classes (_.cls) and triggers (_.trigger). It ensures consistency, readability, and maintainability across your Salesforce codebase by enforcing naming conventions, code structure, and key Salesforce coding guidelines.
This LWC Template Structure rule defines guidelines to ensure consistent structure and readability in Lightning web component (LWC) HTML templates. By enforcing these conventions, you make sure that your LWC templates follow best practices and remain easy to understand and maintain across your team.
Here are some helpful tips to keep in mind while creating custom rules:
-
Stick to one file type per rule—this practice makes it easier to manage your rules and reduces confusion.
-
Be clear and precise—simple, straightforward rules are easier to understand and follow.
-
Try them out—test your rules with different AI features to make sure that they work as expected.
-
Keep them fresh—revisit and update your rules regularly to stay aligned with evolving project needs.