salesforce-apex-quality

Enforces Apex code quality rules covering governor limits, sharing models, CRUD/FLS security, and test coverage.

38.5k|4.9k|Updated Jun 11, 2025
One-click install
npx skills add https://github.com/github/awesome-copilot --skill salesforce-apex-quality
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: salesforce-apex-quality
Source: https://github.com/github/awesome-copilot/tree/main/skills/salesforce-apex-quality
Command: npx skills add https://github.com/github/awesome-copilot --skill salesforce-apex-quality

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Apex code that passes a quick review often hides governor limit violations, missing sharing declarations, SOQL injection risks, and inadequate test coverage that only surface in production. This Skill applies a systematic checklist to every Apex class, trigger, and test file so these defects are caught before deployment.

Core Features & Use Cases

  • Governor Limit Guardrails: Detects SOQL and DML statements inside loops and enforces bulkified collection-based patterns.
  • Security Enforcement: Verifies sharing model declarations, CRUD/FLS checks, WITH USER_MODE queries, and SOQL injection prevention via bind variables and whitelists.
  • PNB Test Coverage: Requires Positive, Negative, and Bulk (200-251 records) test paths with meaningful assertions using modern Assert methods.
  • Use Case: When reviewing a new Account trigger handler, apply this Skill to confirm the trigger delegates to a with-sharing handler class, all SOQL is bulkified outside loops, and the test class covers positive, negative, and 200-record bulk scenarios.

Quick Start

Review my Apex trigger handler and test class for governor limit risks, sharing model issues, and missing bulk test coverage.

Frequently Asked Questions about salesforce-apex-quality

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent SOQL governor limit errors in Apex?

Never place SOQL queries or DML statements inside for loops. Instead, collect record IDs into a Set, query once before the loop using an IN clause, and perform a single DML operation after the loop on the collected records.

How to enforce CRUD and FLS security in Apex code?

Use WITH USER_MODE in SOQL queries (API 56.0+), pass AccessLevel.USER_MODE to Database.query, or check Schema.sObjectType field accessibility before reading fields. Any method callable from UI components, REST endpoints, or InvocableMethod must enforce these checks.

What sharing declaration should an Apex class use?

Use 'with sharing' as the default for service, handler, selector, and controller classes. Use 'without sharing' only for elevated system operations with a documented reason, and 'inherited sharing' for framework entry points that respect the caller's context.

How do I prevent SOQL injection in Salesforce?

Always use bind variables (:variableName) instead of concatenating user input into query strings. For dynamic SOQL with user-controlled field names, validate the input against a whitelist of allowed fields before executing the query.

What is PNB test coverage in Apex?

PNB stands for Positive, Negative, and Bulk testing. Every feature needs tests for expected inputs, error conditions with proper exception assertions, and bulk operations processing 200-251 records in a single transaction using Test.startTest and Test.stopTest.

Why should Apex triggers not contain business logic?

Trigger bodies should only contain context checks, handler invocation, and routing logic. Business logic, SOQL, and DML belong in a handler class, keeping one trigger per object and extending any existing trigger framework rather than creating parallel patterns.