Copilot Instructions — AI Ruleset for Apex & LWC
This guide shows how to create a Salesforce-specific AI ruleset for GitHub Copilot that enforces best practices in Apex and LWC development. By using a single always-on copilot-instructions.md file, teams can prevent common mistakes like SOQL in loops, legacy LWC directives, and missing test coverage automatically. The ruleset integrates seamlessly with GitHub Copilot, providing consistent, project-wide coding standards without configuration. Teams can quickly validate their setup with targeted prompts and scale it by adding specialized Copilot Agent Skills for deeper expertise.
- Implement a single copilot-instructions.md file for project-wide AI code guidance.
- Follow the seven-section ruleset to prevent common Apex and LWC mistakes.
- Use the layered .github folder with rulesets and skills for balanced AI assistance.
- Validate Copilot output with targeted prompts for triggers, LWC, testing, async, and events.
- Clone and share the GitHub repository to enforce consistent coding standards team-wide.
A practical AI ruleset for Apex and LWC, copy-paste-ready guide to writing copilot instructions (AI Coding Rules for tools like Github Copilot, Cursor, Agentforce Vibes or Claude Code) — so every AI-generated Salesforce class, trigger, and LWC component meets production standards from the first prompt. Key Takeaways Copilot instructions (AI Coding Ruleset) live in .github/copilot-instructions.md and activate automatically on every prompt — zero setup required. The AI Coding rules covers seven sections: Role Preamble, Architecture, Apex Rules, Naming, Formatting, LWC Rules, and Testing & Security. Together, these 92 lines prevent the most common AI mistakes — SOQL in loops, legacy LWC directives, hardcoded IDs, and missing test coverage. The full ruleset, skills, and deep-dive coding rules are available on GitHub . This post is Part 2 of the series. Part 1 covers Copilot Agent Skills .