---
schema_version: "1"
id: f9fe469efe9a97c672d178d56c61f895eb1ad20a5da14d386d1596c7f8aa9fdb
title: Agentforce Rules
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/salesforcedx/einsteinfordevs/guides/files/devagent-rules.md
canonical_url: https://developer.salesforce.com/docs/platform/einstein-for-devs/guide/devagent-rules.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 02056bcef991faa271f4163b63b5b94d4d02009ed67df3eb429100eff9ff6273
products:
  - Agentforce Vibes Developer Guide (Deprecated)
  - salesforcedx
---
# 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](https://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.

## Create Rules

Quickly create rules through Agentforce's built-in interface:

1. **Access Rules Tab**: Click Rules & Workflows (⚖️ icon) in the Agentforce chat interface.
2. **Select Rule Type**: Select either Global Rule or Workspace Rule.
3. **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.

### How Rules Work

Rules are loaded when Agentforce starts a task. Here’s what happens:

Agentforce checks for rules in this sequence:

1. `.a4drules`/ folder (all .md files inside)
2. Single `.a4drules` file
3. `agents.md`file

- 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.

### Managing Rules with the Interface

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.

## Customization Rules Format

Use this simple rules format to create your custom rules:

```
# Rule: [Rule Name]

**Description:** [Brief description of the rule's purpose]

**Guidelines:**
- [Guideline 1]
- [Guideline 2]
```

## Examples of Customization 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.

### Apex Naming Convention and Best Practices Rules

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.

```
# Rule: Apex Best Practices

**Description:** Enforce some best practices and naming and formatting standards for Apex code

**Guidelines**
- Class names must be PascalCase (For example: `AccountService`)
- Method names must be camelCase
- Constants must be UPPER_SNAKE_CASE
- Use `@isTest` and `seeAllData=false` for all test classes
- Variable names must be camelCase and descriptive (For example: `accountList` or `isClosed`)
- Boolean variable names should start with 'is', 'has' ', or 'can' (For example: `isActive` or `hasAccess` )
- Use plural names for collections (For example: `contacts` or `accountsMap` )
- Avoid abbreviations and single-letter variables (For example: `account`, not `acc`)
- Avoid SOQL or DML inside 'for' loops. Use Maps and Sets to bulkify logic.
- DML should be in the user mode. For example: `insert as user` or `update as user`.
- Use `WITH USER_MODE` explicitly for SOQL queries
- Test classes must use PascalCase and end with 'Test' (For example: `AccountServiceTest`)
- Test method names should describe the test scenario clearly (For example: `testCalculateTax_WithValidInput`)
- When writing Asserts always use the `System.Assert `class instead of `System assert`
```

### LWC Template Structure Rules

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.

```
# Rule: LWC Template Structure

**Description:** Maintain consistent structure in LWC HTML files.

**Guidelines:**
- Wrap all content in a root `<template>` tag
- Use a top-level `<div class="component-name">` block
- Group conditional rendering (`if:true`/`if:false`) elements together
- Include a comment block before each major section
```

## Best Practices

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.
