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 |
references/AccountSelector.cls
View on GitHub/**
* Selector class for Account queries.
* Encapsulates all SOQL for Account records.
* All methods return bulkified results (Lists or Maps).
*/
public with sharing class AccountSelector {
// ─── Field Lists ─────────────────────────────────────────────────────
/**
* Returns the default set of fields to query for Account.
* 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',
'AccountNumber',
'Type',
'Industry',
'AnnualRevenue',
'NumberOfEmployees',
'Phone',
'Website',
'OwnerId',
'CreatedDate',
'LastModifiedDate'
},
', '
);
}
/**
* Returns fields needed for billing/territory operations
* @return Comma-separated field list as a String
*/
private static String getBillingFields() {
return String.join(
new List<String>{
'Id',
'Name',
'BillingStreet',
'BillingCity',
'BillingState',
'BillingPostalCode',
'BillingCountry',
'Territory__c'
},
', '
);
}
// ─── Query Methods ───────────────────────────────────────────────────
/**
* Selects Account records by their Ids
* @param recordIds Set of Account Ids to query
* @return List of Account records matching the provided Ids
* @example
* Set<Id> ids = new Set<Id>{ '001xx000003DGbY' };
* List<Account> results = AccountSelector.selectByIds(ids);
*/
public static List<Account> selectByIds(Set<Id> recordIds) {
if (recordIds == null || recordIds.isEmpty()) {
return new List<Account>();
}
return Database.query(
'SELECT ' + getDefaultFields() +
' FROM Account' +
' WHERE Id IN :recordIds'
);
}
/**
* Selects Account records as a Map keyed by Id
* @param recordIds Set of Account Ids to query
* @return Map of Id to Account
*/
public static Map<Id, Account> selectMapByIds(Set<Id> recordIds) {
return new Map<Id, Account>(selectByIds(recordIds));
}
/**
* Selects Accounts with billing address fields for territory assignment
* @param recordIds Set of Account Ids to query
* @return List of Account records with billing address fields populated
*/
public static List<Account> selectWithBillingAddress(Set<Id> recordIds) {
if (recordIds == null || recordIds.isEmpty()) {
return new List<Account>();
}
return Database.query(
'SELECT ' + getBillingFields() +
' FROM Account' +
' WHERE Id IN :recordIds'
);
}
/**
* Selects Accounts by Account Type
* @param accountTypes Set of Account Type values to filter by
* @return List of matching Account records
* @example
* List<Account> prospects = AccountSelector.selectByType(
* new Set<String>{ 'Prospect', 'Customer - Direct' }
* );
*/
public static List<Account> selectByType(Set<String> accountTypes) {
if (accountTypes == null || accountTypes.isEmpty()) {
return new List<Account>();
}
return Database.query(
'SELECT ' + getDefaultFields() +
' FROM Account' +
' WHERE Type IN :accountTypes' +
' ORDER BY Name ASC'
);
}
/**
* Selects Accounts by Industry with a minimum annual revenue
* @param industries Set of Industry values to filter by
* @param minRevenue Minimum AnnualRevenue threshold
* @return List of matching Account records ordered by revenue descending
* @example
* List<Account> techAccounts = AccountSelector.selectByIndustryAndRevenue(
* new Set<String>{ 'Technology' },
* 1000000
* );
*/
public static List<Account> selectByIndustryAndRevenue(Set<String> industries, Decimal minRevenue) {
if (industries == null || industries.isEmpty()) {
return new List<Account>();
}
Decimal revenueThreshold = minRevenue ?? 0;
return Database.query(
'SELECT ' + getDefaultFields() +
' FROM Account' +
' WHERE Industry IN :industries' +
' AND AnnualRevenue >= :revenueThreshold' +
' ORDER BY AnnualRevenue DESC'
);
}
/**
* Selects Accounts with their related Contacts (subquery)
* @param recordIds Set of Account Ids to query
* @return List of Account records with nested Contacts
*/
public static List<Account> selectWithContacts(Set<Id> recordIds) {
if (recordIds == null || recordIds.isEmpty()) {
return new List<Account>();
}
return [
SELECT Id, Name, Type, Industry,
(SELECT Id, FirstName, LastName, Email, Title
FROM Contacts
ORDER BY LastName ASC)
FROM Account
WHERE Id IN :recordIds
];
}
// ─── Aggregate Queries ───────────────────────────────────────────────
/**
* Returns a count of Accounts grouped by Industry
* @return List of AggregateResult with Industry and record count
* @example
* List<AggregateResult> results = AccountSelector.countByIndustry();
* for (AggregateResult ar : results) {
* System.debug(ar.get('Industry') + ': ' + ar.get('cnt'));
* }
*/
public static List<AggregateResult> countByIndustry() {
return [
SELECT Industry, COUNT(Id) cnt
FROM Account
WHERE Industry != NULL
GROUP BY Industry
ORDER BY COUNT(Id) DESC
];
}
}
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 |