Agentforce Rules

Agentforce Rules allow you to provide system-level guidance and persistent context for your Salesforce development projects. Think of rules as a way to establish consistent patterns, coding standards, and project-specific preferences that Agentforce follows throughout your development sessions. Rules work as persistent instructions that help maintain consistency across your development work. Unlike one-time prompts, rules provide ongoing guidance that influences how Agentforce approaches tasks, suggests solutions, and follows your team's established patterns.

We also provide a set of out-of-the-box rules to help with your Salesforce development. Click Rules & Workflows (justice icon) to see the list of global OOTB rules. You can toggle these rules on or off (with a4d-general-rules-no-edit.md enabled by default). You may edit them if you wish, but note that any changes will be overwritten when the extension is updated.

Key benefits:

  • Consistent Standards: Enforce coding patterns and architectural decisions.
  • Project Context: Maintain Salesforce org structure and business requirements.
  • Team Alignment: Share practices across development teams.
  • Quality Assurance: 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:

  1. Access Rules Tab: Click Rules & Workflows (justice icon) in the Agentforce chat interface.
  2. Choose Rule Type: Select either Global Rule or Workspace Rule.
  3. Create New Rule: Click + to create a new 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.

Agentforce provides a convenient popover interface that allows you to:

  • View Active Rules: See which global and workspace rules are currently active.
  • Toggle Rules: Enable or disable specific rules with a single click.
  • Add or Delete Rules: 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 code is generated, 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 ensure 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 they work as expected.

Keep them fresh – Revisit and update your rules regularly to stay aligned with evolving project needs.