salesforce-apex-quality

Featured

Apex code quality guardrails for Salesforce development. Enforces bulk-safety rules (no SOQL/DML in loops), sharing model requirements, CRUD/FLS security, SOQL injection prevention, PNB test coverage (Positive / Negative / Bulk), and modern Apex idioms. Use this skill when reviewing or generating Apex classes, trigger handlers, batch jobs, or test classes to catch governor limit risks, security gaps, and quality issues before deployment.

AI & Automation 41,313 stars 5382 forks Updated today MIT

Install

View on GitHub

Quality Score: 93/100

Stars 20%
100
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# Salesforce Apex Quality Guardrails Apply these checks to every Apex class, trigger, and test file you write or review. ## Step 1 — Governor Limit Safety Check Scan for these patterns before declaring any Apex file acceptable: ### SOQL and DML in Loops — Automatic Fail ```apex // ❌ NEVER — causes LimitException at scale for (Account a : accounts) { List<Contact> contacts = [SELECT Id FROM Contact WHERE AccountId = :a.Id]; // SOQL in loop update a; // DML in loop } // ✅ ALWAYS — collect, then query/update once Set<Id> accountIds = new Map<Id, Account>(accounts).keySet(); Map<Id, List<Contact>> contactsByAccount = new Map<Id, List<Contact>>(); for (Contact c : [SELECT Id, AccountId FROM Contact WHERE AccountId IN :accountIds]) { if (!contactsByAccount.containsKey(c.AccountId)) { contactsByAccount.put(c.AccountId, new List<Contact>()); } contactsByAccount.get(c.AccountId).add(c); } update accounts; // DML once, outside the loop ``` Rule: if you see `[SELECT` or `Database.query`, `insert`, `update`, `delete`, `upsert`, `merge` inside a `for` loop body — stop and refactor before proceeding. ## Step 2 — Sharing Model Verification Every class must declare its sharing intent explicitly. Undeclared sharing inherits from the caller — unpredictable behaviour. | Declaration | When to use | |---|---| | `public with sharing class Foo` | Default for all service, handler, selector, and controller classes | | `public without sharing class Foo` | Only whe...

Details

Author
github
Repository
github/awesome-copilot
Created
1 years ago
Last Updated
today
Language
JavaScript
License
MIT

Similar Skills

Semantically similar based on skill content — not just same category