Apex
Apex是一款code方向的AI技能,核心价值是Guidelines and best practices for Apex development on the Salesforce Platform,可用于解决开发者在code领域的实际问题,帮助用户提升效率、自动化重复任务或优化工作流。
Guidelines and best practices for Apex development on the Salesforce Platform
mkdir -p ./skills/apex && curl -sfL https://raw.githubusercontent.com/github/awesome-copilot/main/skills/apex/SKILL.md -o ./skills/apex/SKILL.md Run in terminal / PowerShell. Requires curl (Unix) or PowerShell 5+ (Windows).
Skill Content
# Apex Development
General Instructions
- Always use the latest Apex features and best practices for the Salesforce Platform.
- Write clear and concise comments for each class and method, explaining the business logic and any complex operations.
- Handle edge cases and implement proper exception handling with meaningful error messages.
- Focus on bulkification - write code that handles collections of records, not single records.
- Be mindful of governor limits and design solutions that scale efficiently.
- Implement proper separation of concerns using service layers, domain classes, and selector classes.
- Document external dependencies, integration points, and their purposes in comments.
Naming Conventions
- **Classes**: Use `PascalCase` for class names. Name classes descriptively to reflect their purpose.
- Controllers: suffix with `Controller` (e.g., `AccountController`)
- Trigger Handlers: suffix with `TriggerHandler` (e.g., `AccountTriggerHandler`)
- Service Classes: suffix with `Service` (e.g., `AccountService`)
- Selector Classes: suffix with `Selector` (e.g., `AccountSelector`)
- Test Classes: suffix with `Test` (e.g., `AccountServiceTest`)
- Batch Classes: suffix with `Batch` (e.g., `AccountCleanupBatch`)
- Queueable Classes: suffix with `Queueable` (e.g., `EmailNotificationQueueable`)
- **Methods**: Use `camelCase` for method names. Use verbs to indicate actions.
- Good: `getActiveAccounts()`, `updateContactEmail()`, `deleteExpiredRecords()`
- Avoid abbreviations: `getAccs()` → `getAccounts()`
- **Variables**: Use `camelCase` for variable names. Use descriptive names.
- Good: `accountList`, `emailAddress`, `totalAmount`
- Avoid single letters except for loop counters: `a` → `account`
- **Constants**: Use `UPPER_SNAKE_CASE` for constants.
- Good: `MAX_BATCH_SIZE`, `DEFAULT_EMAIL_TEMPLATE`, `ERROR_MESSAGE_PREFIX`
- **Triggers**: Name triggers as `ObjectName` + trigger event (e.g., `AccountTrigger`, `ContactTrigger`)
Best Practices
Bulkification
- **Always write bulkified code** - Design all code to handle collections of records, not individual records.
- Avoid SOQL queries and DML statements inside loops.
- Use collections (`List<>`, `Set<>`, `Map<>`) to process multiple records efficiently.
// Good Example - Bulkified
public static void updateAccountRating(List<Account> accounts) {
for (Account acc : accounts) {
if (acc.AnnualRevenue > 1000000) {
acc.Rating = 'Hot';
}
}
update accounts;
}
// Bad Example - Not bulkified
public static void updateAccountRating(Account account) {
if (account.AnnualRevenue > 1000000) {
account.Rating = 'Hot';
update account; // DML in a method designed for single records
}
}Maps for O(1) Lookup
- **Use Maps for efficient lookups** - Convert lists to maps for O(1) constant-time lookups instead of O(n) list iterations.
- Use `Map<Id, SObject>` constructor to quickly convert query results to a map.
- Ideal for matching related records, lookups, and avoiding nested loops.
// Good Example - Using Map for O(1) lookup
Map<Id, Account> accountMap = new Map<Id, Account>([
SELECT Id, Name, Industry FROM Account WHERE Id IN :accountIds
]);
for (Contact con : contacts) {
Account acc = accountMap.get(con.AccountId);
if (acc != null) {
con.Industry__c = acc.Industry;
}
}
// Bad Example - Nested loop with O(n²) complexity
List<Account> accounts = [SELECT Id, Name, Industry FROM Account WHERE Id IN :accountIds];
for (Contact con : contacts) {
for (Account acc : accounts) {
if (con.AccountId == acc.Id) {
con.Industry__c = acc.Industry;
break;
}
}
}
// Good Example - Map for grouping records
Map<Id, List<Contact>> contactsByAccountId = new Map<Id, List<Contact>>();
for (Contact con : contacts) {
if (!contactsByAccountId.containsKey(con.AccountId)) {
contactsByAccountId.put(con.Acco🎯 Best For
- UI designers
- Product designers
- Claude users
- GitHub Copilot users
- Software engineers
💡 Use Cases
- Generating component mockups
- Creating design system tokens
- Code quality improvement
- Best practice enforcement
📖 How to Use This Skill
- 1
Install the Skill
Copy the install command from the Terminal tab and run it. The SKILL.md file downloads to your local skills directory.
- 2
Load into Your AI Assistant
Open Claude or GitHub Copilot and reference the skill. Paste the SKILL.md content or use the system prompt tab.
- 3
Apply Apex to Your Work
Open your project in the AI assistant and ask it to apply the skill. Start with a small module to verify the output quality.
- 4
Review and Refine
Review AI suggestions before committing. Run tests, check for regressions, and iterate on the skill output.
❓ Frequently Asked Questions
Does this work with Figma?
Some design skills integrate with Figma plugins. Check the Works With section for supported tools.
Is Apex compatible with Cursor and VS Code?
Yes — this skill works with any AI coding assistant including Cursor, VS Code with Copilot, and JetBrains IDEs.
Do I need specific dependencies for Apex?
Check the install command and Works With section. Most code skills only require the AI assistant and your codebase.
How do I install Apex?
Copy the install command from the Terminal tab and run it. The skill downloads to ./skills/apex/SKILL.md, ready to use.
Can I customize this skill for my team?
Absolutely. Edit the SKILL.md file to add team-specific instructions, examples, or workflows.
⚠️ Common Mistakes to Avoid
Skipping usability testing
AI-generated designs should be validated with real users before development.
Skipping validation
Always test AI-generated code changes, even for simple refactors.
Missing dependency updates
Check if the skill requires updated dependencies or new packages.