afv-library/skills/apex-class/templates/selector.cls
Mohan Raj Rajamanickam 2320c50264
ci: publish skills as @salesforce/afv-skills npm package @W-21534193@ (#30)
* ci: update package details and add GitHub workflows for skills validation and release

* chore: update Node version, change license, and refactor skills validation script to TypeScript

* chore: remove unused deps

* fix: npm package

* fix: flatten skills to pass validation

* chore: add validation script to package.json and update GitHub workflow to use it

* chore: enhance skills validation and update workflows for npm publishing

* refactor: streamline skills validation process in workflow and script

* refactor: improve documentation and structure of skills validation script

* implement checks based on jeff's best practices doc

* chore: add pull request template for skill submissions

* chore: update pull request template with additional references and improve automated checks section

* chore: update pull request template to clarify naming convention with a warning for gerund form

* chore: update pull request template to reference skill authoring guide and enhance checklist structure

* chore: enhance GitHub workflows for skills validation and release process

* refactor: improve parsing logic for SKILL.md files and enhance error collection in validation

* chore: update validation checks to enforce character limits for skill names and descriptions

* fix: remove unnecessary whitespace in footer string in validate-skills.ts
2026-03-12 13:41:52 -07:00

93 lines
3.5 KiB
OpenEdge ABL

/**
* @description Selector class for {SObject} queries.
* Encapsulates all SOQL for {SObject} records.
* All methods return bulkified results (Lists or Maps).
* @author Generated by Apex Class Writer Skill
*/
public with sharing class {SObject}Selector {
// Field Lists
/**
* @description 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
/**
* @description 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'
);
}
/**
* @description 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));
}
/**
* @description 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
/**
* @description Custom exception for query errors
*/
public class QueryException extends Exception {}
}