SEL_Base
Class · Group: Selectors
global abstract inherited sharing class SEL_Base implements IF_QueryableImplements: IF_Queryable
Known Derived Types: SEL_ApiCall, SEL_ApiIssue, SEL_ContentVersion, SEL_EmailTemplate, SEL_Foobar, SEL_Group, SEL_OrgWideEmailAddress, SEL_PermissionSet, SEL_PermissionSetGroup, SEL_Profile, SEL_User, SEL_UserRole, IF_Queryable.count(), IF_Queryable.exists(), IF_Queryable.getFirst(), IF_Queryable.toList(), IF_Queryable.toQueryLocator()
Abstract base class for all selectors. Provides lazy-loaded field management and IF_Queryable implementation. Subclasses define their SObjectType and core fields; the base class handles query builder creation with all configured fields.
Since: 1.0
Example:
global class SEL_Account extends SEL_Base
{
global SEL_Account()
{
super(Account.SObjectType);
}
global override List<SObjectField> getFields()
{
return new List<SObjectField> { Account.Id, Account.Name };
}
global override List<String> getFieldPaths()
{
return new List<String> { 'Owner.Name', 'CreatedBy.Email' };
}
global List<Account> findByIndustry(String industry)
{
return query.condition(Account.Industry).equals(industry).toList();
}
}See Also: IF_Queryable
Properties
| Property | Description |
|---|---|
| global final List fieldPaths | Core field path strings for this selector, supporting relationship traversal syntax (e.g., 'Owner.Name'). |
| global final List fields | Core SObjectField tokens for this selector. |
| global QRY_Builder.Builder query | Returns a new query builder pre-configured with this selector's SObjectType and all field sources. |
Methods
| Method | Description |
|---|---|
| global Integer count() | Returns the count of all records matching the default query. |
| global Boolean exists() | Returns true if any records match the default query. |
| global List findByField(SObjectField field, List<Object> values) | Finds records matching multiple values on a field. |
| global List findByField(SObjectField field, Object value) | Finds records matching a single field value. |
| global List findByField(SObjectField field, Set<Object> values) | Finds records matching multiple values on a field. |
| global List findByFields(Map<SObjectField, Object> fieldValues) | Finds records matching multiple field-value pairs combined with AND logic. |
| global SObject findById(Id recordId) | Finds a single record by its Id. |
| global List findById(Set<Id> recordIds) | Finds multiple records by their Ids. |
| global SObject findByIdOrThrow(Id recordId) | Finds a single record by its Id, throwing NotFoundException if not found. |
| global List findByIdOrThrow(Set<Id> recordIds) | Finds multiple records by their Ids, throwing NotFoundException if any Id is missing. |
| global SObject findFirstByField(SObjectField field, Object value) | Finds the first record matching a single field value, or null if not found. |
| global SObject findFirstByFields(Map<SObjectField, Object> fieldValues) | Finds the first record matching multiple field-value pairs combined with AND logic, or null if not found. |
| global virtual List getFieldPaths() | Returns core field paths as strings, supporting relationship traversal syntax (e.g., 'Owner.Name', 'Contact.Email'). |
| global virtual List getFields() | Returns the core SObjectField tokens always included in queries from this selector. |
| global SObject getFirst() | Executes the default query and returns the first record, or null. |
| global virtual SObject getRandomItem() | Returns a random record matching the default query, or null if none exist. |
| global SEL_Base(SObjectType objectType) | Constructs a selector for the given SObjectType. |
| global virtual Boolean systemModeRequired() | Declares whether this selector's queries must run in AccessLevel.SYSTEM_MODE regardless of the UserModeQueries_Enabled feature flag. |
| global List toList() | Executes the default query and returns all matching records. |
| global Database.QueryLocator toQueryLocator() | Returns a QueryLocator for the default query. |
Property Details
fieldPaths
global final List<String> fieldPathsType: List
Core field path strings for this selector, supporting relationship traversal syntax (e.g., 'Owner.Name'). Lazy-loaded from getCoreFieldPaths() on first access.
Since:
Example:
fields
global final List<SObjectField> fieldsType: List
Core SObjectField tokens for this selector. Lazy-loaded from getCoreFields() on first access. Subscribers can inspect a selector's field configuration via this property.
Since:
Example:
query
global QRY_Builder.Builder queryType: QRY_Builder.Builder
Returns a new query builder pre-configured with this selector's SObjectType and all field sources. Each access creates a fresh builder instance to prevent state leaking between queries. When systemModeRequired() returns true, the builder has systemModeInternal() applied so framework-internal reads (CMDT, framework-owned sObjects) run in SYSTEM_MODE without polluting the BypassEvent audit trail — a static systemModeRequired() design choice is not a runtime bypass. Selectors that leave systemModeRequired() at the default (false) inherit the UserModeQueries_Enabled flag-driven default.
Since:
Example:
Method Details
SEL_Base
global SEL_Base(SObjectType objectType)Constructs a selector for the given SObjectType.
Parameters:
objectType(SObjectType) - The SObjectType this selector queries
Since: 1.0
Example:
SEL_Account.SEL_Base instance = new SEL_Account.SEL_Base(Account.SObjectType);count
global Integer count()Returns the count of all records matching the default query.
Returns: Integer - Number of matching records
Since: 1.0
Example:
Integer result = instance.count();exists
global Boolean exists()Returns true if any records match the default query.
Returns: Boolean - True if at least one record matches
Since: 1.0
Example:
Boolean result = instance.exists();findByField
global List<SObject> findByField(SObjectField field, List<Object> values)Finds records matching multiple values on a field.
Parameters:
field(SObjectField) - The SObjectField to filter onvalues(List) - The values to match
Returns: SObject - List of matching records, or empty list if no values provided
Since: 1.0
Example:
List<SObject> result = instance.findByField(Account.Name, new List<Object>{'a', 'b'});findByField
global List<SObject> findByField(SObjectField field, Object value)Finds records matching a single field value.
Parameters:
field(SObjectField) - The SObjectField to filter onvalue(Object) - The value to match
Returns: SObject - List of matching records
Since: 1.0
Example:
List<SObject> result = instance.findByField(Account.Name, 'value');findByField
global List<SObject> findByField(SObjectField field, Set<Object> values)Finds records matching multiple values on a field.
Parameters:
field(SObjectField) - The SObjectField to filter onvalues(Set) - The values to match
Returns: SObject - List of matching records, or empty list if no values provided
Since: 1.0
Example:
List<SObject> result = instance.findByField(Account.Name, new Set<Object>{'value'});findByFields
global List<SObject> findByFields(Map<SObjectField, Object> fieldValues)Finds records matching multiple field-value pairs combined with AND logic.
Parameters:
fieldValues(Map) - Map of SObjectField tokens to their expected values
Returns: SObject - List of matching records, or empty list if fieldValues is null or empty
Since: 1.0
Example:
List<SObject> records = new SEL_Foobar().findByFields
(
new Map<SObjectField, Object>
{
Foobar__c.Text__c => 'Alpha',
Foobar__c.Email__c => 'test@example.com'
}
);findById
global SObject findById(Id recordId)Finds a single record by its Id.
Parameters:
recordId(Id) - The Id of the record to retrieve
Returns: SObject - The matching record or null if not found
Since: 1.0
Example:
SObject result = instance.findById(recordId);findById
global List<SObject> findById(Set<Id> recordIds)Finds multiple records by their Ids.
Parameters:
recordIds(Set) - The set of Ids to retrieve
Returns: SObject - List of matching records, or empty list if no Ids provided
Since: 1.0
Example:
List<SObject> result = instance.findById(recordIds);findByIdOrThrow
global SObject findByIdOrThrow(Id recordId)Finds a single record by its Id, throwing NotFoundException if not found.
Parameters:
recordId(Id) - The Id of the record to retrieve
Returns: SObject - The matching record
Throws:
- UTIL_Exceptions.NotFoundException - If no record exists with the given Id
Since: 1.0
Example:
Foobar__c record = (Foobar__c)new SEL_Foobar().findByIdOrThrow(recordId);findByIdOrThrow
global List<SObject> findByIdOrThrow(Set<Id> recordIds)Finds multiple records by their Ids, throwing NotFoundException if any Id is missing.
Parameters:
recordIds(Set) - The set of Ids to retrieve
Returns: SObject - List of matching records
Throws:
- UTIL_Exceptions.NotFoundException - If any of the requested Ids were not found
Since: 1.0
Example:
List<Foobar__c> records = new SEL_Foobar().findByIdOrThrow(recordIds);findFirstByField
global SObject findFirstByField(SObjectField field, Object value)Finds the first record matching a single field value, or null if not found.
Parameters:
field(SObjectField) - The SObjectField to filter onvalue(Object) - The value to match
Returns: SObject - The first matching record or null
Since: 1.0
Example:
SObject result = instance.findFirstByField(Account.Name, 'value');findFirstByFields
global SObject findFirstByFields(Map<SObjectField, Object> fieldValues)Finds the first record matching multiple field-value pairs combined with AND logic, or null if not found.
Parameters:
fieldValues(Map) - Map of SObjectField tokens to their expected values
Returns: SObject - The first matching record or null
Since: 1.0
Example:
SObject record = new SEL_Foobar().findFirstByFields
(
new Map<SObjectField, Object>
{
Foobar__c.Text__c => 'Alpha',
Foobar__c.Email__c => 'test@example.com'
}
);getFieldPaths
global virtual List<String> getFieldPaths()Returns core field paths as strings, supporting relationship traversal syntax (e.g., 'Owner.Name', 'Contact.Email'). Override to include relationship fields in the default query. Returns an empty list by default.
Returns: String - List of field path strings
Since: 1.0
Example:
List<String> result = instance.getFieldPaths();getFields
global virtual List<SObjectField> getFields()Returns the core SObjectField tokens always included in queries from this selector. Override to define the default field set. Returns an empty list by default.
Returns: SObjectField - List of core SObjectFields
Since: 1.0
Example:
List<SObjectField> result = instance.getFields();getFirst
global SObject getFirst()Executes the default query and returns the first record, or null.
Returns: SObject - First matching record or null
Since: 1.0
Example:
SObject result = instance.getFirst();getRandomItem
global virtual SObject getRandomItem()Returns a random record matching the default query, or null if none exist.
Returns: SObject - A random matching record or null
Since: 1.0
Example:
SObject result = instance.getRandomItem();systemModeRequired
global virtual Boolean systemModeRequired()Declares whether this selector's queries must run in AccessLevel.SYSTEM_MODE regardless of the UserModeQueries_Enabled feature flag. Framework-internal selectors that read CMDT, framework-owned sObjects, or system-schema tables override this to return true so they continue working when the running user lacks FLS/CRUD on those objects by design.
Subscriber-reachable selectors should leave this at the default (false) so they inherit the flag-driven default — secure-by-default when the flag is enabled.
Returns: Boolean - true when this selector's queries must run in SYSTEM_MODE.
Since: 1.0
Example:
public inherited sharing class SEL_Cases extends SEL_Base
{
public SEL_Cases()
{
super(Case.SObjectType);
}
public override Boolean systemModeRequired()
{
return true;
}
}toList
global List<SObject> toList()Executes the default query and returns all matching records.
Returns: SObject - List of all records with default fields
Since: 1.0
Example:
List<SObject> result = instance.toList();toQueryLocator
global Database.QueryLocator toQueryLocator()Returns a QueryLocator for the default query. Suitable for batch processing.
Returns: Database.QueryLocator - QueryLocator for the default query
Since: 1.0
Example:
global class BatchProcessAccounts implements Database.Batchable
{
global Database.QueryLocator start(Database.BatchableContext context)
{
return new SEL_Account().toQueryLocator();
}
}