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/batch.cls
View on GitHub/**
* Batch Apex class for {describe the batch operation}.
* Processes {SObject} records in configurable batch sizes.
* Implements Database.Stateful to track cumulative results across chunks.
*
* @example
* // Execute with default batch size
* Database.executeBatch(new {ClassName}());
*
* // Execute with custom batch size
* Database.executeBatch(new {ClassName}(), 100);
*/
public with sharing class {ClassName} implements Database.Batchable<SObject>, Database.Stateful {
// ─── Constants ───────────────────────────────────────────────────────
private static final Integer DEFAULT_BATCH_SIZE = 200;
// ─── Stateful Tracking ───────────────────────────────────────────────
private Integer totalProcessed = 0;
private Integer totalErrors = 0;
private List<String> errorMessages = new List<String>();
// ─── Constructor ─────────────────────────────────────────────────────
/**
* Default constructor
*/
public {ClassName}() {
// Default configuration
}
// ─── Batchable Interface ─────────────────────────────────────────────
/**
* Defines the scope of records to process.
* Uses Database.QueryLocator for efficient large-dataset processing.
* @param bc The batch context
* @return QueryLocator for the records to process
*/
public Database.QueryLocator start(Database.BatchableContext bc) {
return Database.getQueryLocator([
SELECT Id, Name
// TODO: Add fields needed for processing
FROM {SObject}
// TODO: Add WHERE clause to scope the records
]);
}
/**
* Processes each batch of records.
* Uses Database.update with allOrNone=false for partial success handling.
* @param bc The batch context
* @param scope List of {SObject} records in the current batch
*/
public void execute(Database.BatchableContext bc, List<{SObject}> scope) {
List<{SObject}> recordsToUpdate = new List<{SObject}>();
for ({SObject} record : scope) {
// TODO: Apply business logic to each record
recordsToUpdate.add(record);
}
if (!recordsToUpdate.isEmpty()) {
List<Database.SaveResult> results = Database.update(recordsToUpdate, false);
processResults(results);
}
}
/**
* Performs post-processing after all batches complete.
* Logs a summary of the batch execution.
* @param bc The batch context
*/
public void finish(Database.BatchableContext bc) {
String summary = String.format(
'{0} completed. Processed: {1}, Errors: {2}',
new List<Object>{
{ClassName}.class.getName(),
totalProcessed,
totalErrors
}
);
System.debug(LoggingLevel.INFO, summary);
if (!errorMessages.isEmpty()) {
System.debug(LoggingLevel.ERROR, 'Error details: ' + String.join(errorMessages, '\n'));
}
// TODO: Send completion notification email or post to chatter if needed
}
// ─── Private Helpers ─────────────────────────────────────────────────
/**
* Processes Database.SaveResult list, tracking successes and failures
* @param results List of SaveResult from a DML operation
*/
private void processResults(List<Database.SaveResult> results) {
for (Database.SaveResult result : results) {
if (result.isSuccess()) {
totalProcessed++;
} else {
totalErrors++;
for (Database.Error err : result.getErrors()) {
errorMessages.add(
'Record ' + result.getId() + ': ' +
err.getStatusCode() + ' - ' + err.getMessage()
);
}
}
}
}
// ─── Static Helpers ──────────────────────────────────────────────────
/**
* Convenience method to execute with default batch size
* @return The batch job Id
*/
public static Id run() {
return Database.executeBatch(new {ClassName}(), DEFAULT_BATCH_SIZE);
}
}
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 |