forcedotcom/sf-skills / plugins/builder/salesforce-development/skills/platform-apex-generate
platform-apex-generate
VerifiedPrimary Apex authoring skill for class generation, refactoring, and review. ALWAYS ACTIVATE when the user mentions Apex, .cls, triggers, or asks to create/refactor a class (service, selector, domain, batch, queueable, schedulable, invocable, DTO, utility, interface, abstract, exception, REST resource). Use this skill for requests involving SObject CRUD, mapping collections, fetching related records, scheduled jobs, batch jobs, trigger design, @AuraEnabled controllers, @RestResource endpoints, custom REST APIs, or code review of existing Apex.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 22.0 KB |
| assets/abstract.cls | other | 5.1 KB |
| assets/batch.cls | other | 4.8 KB |
| assets/domain.cls | other | 4.1 KB |
| assets/dto.cls | other | 3.5 KB |
| assets/exception.cls | other | 1.8 KB |
| assets/interface.cls | other | 747 B |
| assets/invocable.cls | other | 4.0 KB |
| assets/queueable.cls | other | 3.5 KB |
| assets/rest-resource.cls | other | 11.4 KB |
| assets/schedulable.cls | other | 2.5 KB |
| assets/selector.cls | other | 3.4 KB |
| assets/service.cls | other | 2.8 KB |
| assets/trigger.cls | other | 1.7 KB |
| assets/utility.cls | other | 3.4 KB |
| references/AccountDeduplicationBatch.cls | other | 5.8 KB |
| references/AccountSelector.cls | other | 6.3 KB |
| references/AccountService.cls | other | 7.8 KB |
assets/selector.cls
View on GitHub/**
* Selector class for {SObject} queries.
* Encapsulates all SOQL for {SObject} records.
* All methods return bulkified results (Lists or Maps).
*/
public inherited sharing class {SObject}Selector {
// ─── Field Lists ─────────────────────────────────────────────────────
/**
* Returns the default set of fields to query for {SObject}.
* Centralizes field references to keep queries DRY.
* @return Comma-separated field list as a String
*/
private static String getDefaultFields() {
return String.join(
new List<String>{
'Id',
'Name',
'CreatedDate',
'LastModifiedDate'
// TODO: Add additional fields here
},
', '
);
}
// ─── Query Methods ───────────────────────────────────────────────────
/**
* Selects {SObject} records by their Ids
* @param recordIds Set of {SObject} Ids to query
* @return List of {SObject} records matching the provided Ids
* @example
* Set<Id> ids = new Set<Id>{ '001xx000003DGbY' };
* List<{SObject}> results = {SObject}Selector.selectByIds(ids);
*/
public static List<{SObject}> selectByIds(Set<Id> recordIds) {
if (recordIds == null || recordIds.isEmpty()) {
return new List<{SObject}>();
}
return Database.query(
'SELECT ' + getDefaultFields() +
' FROM {SObject}' +
' WHERE Id IN :recordIds'
);
}
/**
* Selects {SObject} records as a Map keyed by Id
* @param recordIds Set of {SObject} Ids to query
* @return Map of Id to {SObject}
*/
public static Map<Id, {SObject}> selectMapByIds(Set<Id> recordIds) {
return new Map<Id, {SObject}>(selectByIds(recordIds));
}
/**
* Selects {SObject} records by a specific field value
* @param fieldName API name of the field to filter on
* @param values Set of values to match
* @return List of matching {SObject} records
* @example
* List<{SObject}> results = {SObject}Selector.selectByField('Status__c', new Set<String>{ 'Active' });
*/
public static List<{SObject}> selectByField(String fieldName, Set<String> values) {
if (String.isBlank(fieldName) || values == null || values.isEmpty()) {
return new List<{SObject}>();
}
// Validate field name to prevent SOQL injection
Schema.SObjectField field = Schema.SObjectType.{SObject}.fields.getMap().get(fieldName);
if (field == null) {
throw new QueryException('Invalid field name: ' + fieldName);
}
return Database.query(
'SELECT ' + getDefaultFields() +
' FROM {SObject}' +
' WHERE ' + String.escapeSingleQuotes(fieldName) + ' IN :values'
);
}
// ─── Exception ───────────────────────────────────────────────────────
/**
* Custom exception for query errors
*/
public class QueryException extends Exception {}
}
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation). | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| brand-guidelinesanthropics/skillsApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK). | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |