본문으로 건너뛰기
Skillpedia
API 및 서버 (백엔드)40k · #7412

salesforce-apex-quality

하는 일

이 도구는 Salesforce 플랫폼용으로 작성한 코드가 안전하고 효율적인지 확인하는 데 도움을 줍니다. 한 번에 너무 많은 데이터베이스 작업을 하거나, 사용자가 특정 데이터에 접근할 권한이 있는지 확인하지 않는 등 성능이나 보안 문제를 일으키는 흔한 실수를 찾습니다.

사용하는 경우

  • ✓Salesforce용 Apex 코드를 작성하거나 검토할 때.
  • ✓Salesforce의 governor limit 오류를 피하고 싶을 때.
  • ✓코드가 사용자 권한(보안)을 존중하는지 확인하고 싶을 때.

스킬 링크

https://github.com/github/awesome-copilot/blob/main/skills/salesforce-apex-quality/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/github/awesome-copilot/blob/main/skills/salesforce-apex-quality/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“이 Apex 코드가 Salesforce의 보안과 제한 관련 모범 사례를 따르는지 검토해 주세요.”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

도구는 코드에서 문제를 일으키는 알려진 패턴을 분석합니다. 예를 들어 반복문 안에서 데이터베이스를 조회하거나 업데이트하는지 확인합니다. 이는 비효율적이고 시스템을 멈추게 할 수 있습니다. 또 실행하는 사용자의 권한을 존중하도록 설정되어 있는지도 확인합니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

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

// ❌ 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 when the class must run elevated (e.g. system-level logging, trigger bypass). Requires a code comment explaining why.
public inherited sharing class Foo Framework entry points that should respect the caller's sharing context

If a class does not have one of these three declarations, add it before writing anything else.

Step 3 — CRUD / FLS Enforcement

Apex code that reads or writes records on behalf of a user must verify object and field access. The platform does not enforce FLS or CRUD automatically in Apex.

// Check before querying a field
if (!Schema.sObjectType.Contact.fields.Email.isAccessible()) {
    throw new System.NoAccessException();
}

// Or use WITH USER_MODE in SOQL (API 56.0+)
List<Contact> contacts = [SELECT Id, Email FROM Contact WHERE AccountId = :accId WITH USER_MODE];

// Or use Database.query with AccessLevel
List<Contact> contacts = Database.query('SELECT Id, Email FROM Contact', AccessLevel.USER_MODE);

Rule: any Apex method callable from a UI component, REST endpoint, or @InvocableMethod must enforce CRUD/FLS. Internal service methods called only from trusted contexts may use with sharing instead.

Step 4 — SOQL Injection Prevention

// ❌ NEVER — concatenates user input into SOQL string
String soql = 'SELECT Id FROM Account WHERE Name = \'' + userInput + '\'';

// ✅ ALWAYS — bind variable
String soql = [SELECT Id FROM Account WHERE Name = :userInput];

// ✅ For dynamic SOQL with user-controlled field names — validate against a whitelist
Set<String> allowedFields = new Set<String>{'Name', 'Industry', 'AnnualRevenue'};
if (!allowedFields.contains(userInput)) {
    throw new IllegalArgumentException('Field not permitted: ' + userInput);
}

Step 5 — Modern Apex Idioms

Prefer current language features (API 62.0 / Winter '25+):

Old pattern Modern replacement
if (obj != null) { x = obj.Field__c; } x = obj?.Field__c;
x = (y != null) ? y : defaultVal; x = y ?? defaultVal;
System.assertEquals(expected, actual) Assert.areEqual(expected, actual)
System.assert(condition) Assert.isTrue(condition)
[SELECT ... WHERE ...] with no sharing context [SELECT ... WHERE ... WITH USER_MODE]

Step 6 — PNB Test Coverage Checklist

Every feature must be tested across all three paths. Missing any one of these is a quality failure:

Positive Path

  • Expected input → expected output.
  • Assert the exact field values, record counts, or return values — not just that no exception was thrown.

Negative Path

  • Invalid input, null values, empty collections, and error conditions.
  • Assert that exceptions are thrown with the correct type and message.
  • Assert that no records were mutated when the operation should have failed cleanly.

Bulk Path

  • Insert/update/delete 200–251 records in a single test transaction.
  • Assert that all records processed correctly — no partial failures from governor limits.

…

자주 묻는 질문

'governor limit'이란 무엇인가요?

Salesforce가 코드가 처리할 수 있는 작업량을 제한하는 규칙입니다. 플랫폼이 모든 사용자에게 원활하게 작동하도록 하기 위해서입니다.

'SOQL/DML in loops'는 무엇인가요?

데이터베이스 조회(SOQL)나 쓰기 작업(DML, 예를 들어 insert, update, delete)을 반복문 안에서 계속 실행하는 것입니다. 많은 자원을 쓰기 때문에 보통 금지됩니다.

'CRUD/FLS 보안'은 무엇을 뜻하나요?

CRUD(생성, 읽기, 수정, 삭제)는 레코드를 만들고, 읽고, 수정하고, 삭제할 권한에 관한 것입니다. FLS(필드 수준 보안)는 레코드 안의 특정 필드에 접근할 권한에 관한 것입니다. 코드는 사용자가 이런 권한을 가졌는지 확인해야 합니다.

상세 정보

작성자의 원본 설명

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 ga

repo: github/awesome-copilot

인기도

GitHub 스타
40k
순위
#7412
라이선스
MIT
업데이트
2026. 10. 15.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬