Show:                  

fflib_SObjectSelector

Copyright (c), FinancialForce.com, inc All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the FinancialForce.com, inc nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Signature
public abstract with sharing class fflib_SObjectSelector

fflib_SObjectSelector Properties

Name Signature Description
CURRENCY_ISO_CODE_ENABLED
private Boolean CURRENCY_ISO_CODE_ENABLED
Indicates whether the sObject has the currency ISO code field for organisations which have multi-currency enabled.
DEFAULT_SORT_FIELD
private static String DEFAULT_SORT_FIELD
static variables
describeWrapper
private fflib_SObjectDescribe describeWrapper
Describe helper
m_dataAccess
private DataAccess m_dataAccess
m_enforceCRUD
private Boolean m_enforceCRUD
Enforce CRUD Security
m_enforceFLS
private Boolean m_enforceFLS
Enforce FLS Security
m_includeFieldSetFields
private Boolean m_includeFieldSetFields
Should this selector automatically include the FieldSet fields when building queries?
m_orderBy
private String m_orderBy
Order by field
m_sortSelectFields
private Boolean m_sortSelectFields
Sort the query fields in the select statement (defaults to true, at the expense of performance). Switch this off if you need more performant queries.
SF_ID_FIELD
private static String SF_ID_FIELD

Enums

Name Signature Values
DataAccess
public enum DataAccess
LEGACY, USER_MODE, SYSTEM_MODE

fflib_SObjectSelector Constructors

fflib_SObjectSelector()

Constructs the Selector with the default settings
Signature
public fflib_SObjectSelector()

fflib_SObjectSelector(includeFieldSetFields)

Constructs the Selector
Signature
public fflib_SObjectSelector(Boolean includeFieldSetFields)
Parameters
includeFieldSetFields
Type: Boolean
Set to true if the Selector queries are to include Fieldset fields as well

fflib_SObjectSelector(includeFieldSetFields, dataAccess)

Signature
public fflib_SObjectSelector(Boolean includeFieldSetFields, DataAccess dataAccess)

fflib_SObjectSelector(includeFieldSetFields, enforceCRUD, enforceFLS)

Constructs the Selector
Signature
public fflib_SObjectSelector(Boolean includeFieldSetFields, Boolean enforceCRUD, Boolean enforceFLS)
Deprecated
- consider using dataAccess for native platform enforcement of CRUD and FLS
Parameters
includeFieldSetFields
Type: Boolean
Set to true if the Selector queries are to include Fieldset fields as well

fflib_SObjectSelector(includeFieldSetFields, enforceCRUD, enforceFLS, sortSelectFields)

Constructs the Selector
Signature
public fflib_SObjectSelector(Boolean includeFieldSetFields, Boolean enforceCRUD, Boolean enforceFLS, Boolean sortSelectFields)
Deprecated
- consider using dataAccess for native platform enforcement of CRUD and FLS
Parameters
includeFieldSetFields
Type: Boolean
Set to true if the Selector queries are to include Fieldset fields as well
enforceCRUD
Type: Boolean
Enforce CRUD security
enforceFLS
Type: Boolean
Enforce Field Level Security
sortSelectFields
Type: Boolean
Set to false if selecting many columns to skip sorting select fields and improve performance

fflib_SObjectSelector(includeFieldSetFields, enforceCRUD, enforceFLS, sortSelectFields, dataAccess)

Signature
private fflib_SObjectSelector(Boolean includeFieldSetFields, Boolean enforceCRUD, Boolean enforceFLS, Boolean sortSelectFields, DataAccess dataAccess)

fflib_SObjectSelector Methods

addQueryFactorySubselect(parentQueryFactory)

Adds a subselect QueryFactory based on this selector to the given QueryFactor, returns the child QueryFactory
Signature
public fflib_QueryFactory addQueryFactorySubselect(fflib_QueryFactory parentQueryFactory)

addQueryFactorySubselect(parentQueryFactory, includeSelectorFields)

Adds a subselect QueryFactory based on this selector to the given QueryFactor
Signature
public fflib_QueryFactory addQueryFactorySubselect(fflib_QueryFactory parentQueryFactory, Boolean includeSelectorFields)

addQueryFactorySubselect(parentQueryFactory, relationshipName)

Adds a subselect QueryFactory based on this selector to the given QueryFactor, returns the child QueryFactory
Signature
public fflib_QueryFactory addQueryFactorySubselect(fflib_QueryFactory parentQueryFactory, String relationshipName)

addQueryFactorySubselect(parentQueryFactory, relationshipName, includeSelectorFields)

Adds a subselect QueryFactory based on this selector to the given QueryFactor
Signature
public fflib_QueryFactory addQueryFactorySubselect(fflib_QueryFactory parentQueryFactory, String relationshipName, Boolean includeSelectorFields)

assertIsAccessible()

Throws an exception if the SObject indicated by getSObjectType is not accessible to the current user (read access)
Signature
public void assertIsAccessible()
Deprecated
If you utilise the newQueryFactory method this is automatically done for you (unless disabled by the selector)

buildQuerySObjectById()

Constructs the default SOQL query for this selector, see selectSObjectsById and queryLocatorById
Signature
protected String buildQuerySObjectById()

configureQueryFactory(queryFactory, assertCRUD, enforceFLS, includeSelectorFields, access)

Configures a QueryFactory instance according to the configuration of this selector
Signature
private fflib_QueryFactory configureQueryFactory(fflib_QueryFactory queryFactory, Boolean assertCRUD, Boolean enforceFLS, Boolean includeSelectorFields, DataAccess access)

configureQueryFactoryFields(queryFactory, relationshipFieldPath)

Adds the selectors fields to the given QueryFactory using the given relationship path as a prefix // TODO: This should be consistent (ideally) with configureQueryFactory below
Signature
public void configureQueryFactoryFields(fflib_QueryFactory queryFactory, String relationshipFieldPath)

enforceFLS()

Set the selector to enforce FLS Security
Signature
public fflib_SObjectSelector enforceFLS()
Deprecated
-- consider using setDataAccess to enforce native Apex User Mode Operations instead

getDataAccess()

Signature
public DataAccess getDataAccess()

getFieldListBuilder()

Provides access to the builder containing the list of fields base queries are using, this is demand created if one has not already been defined via setFieldListBuilder @depricated See newQueryFactory
Signature
public fflib_StringBuilder.CommaDelimitedListBuilder getFieldListBuilder()

getFieldListString()

Returns in string form a comma delimited list of fields as defined via getSObjectFieldList and optionally getSObjectFieldSetList
Signature
public String getFieldListString()
Deprecated
See newQueryFactory

getOrderBy()

Override this method to control the default ordering of records returned by the base queries, defaults to the name field of the object if it is not encrypted or CreatedDate if there the object has createdDated or Id
Signature
public virtual String getOrderBy()

getRelatedFieldListString(relation)

Returns in string form a comma delimited list of fields as defined via getSObjectFieldList and optionally getSObjectFieldSetList @depricated See newQueryFactory
Signature
public String getRelatedFieldListString(String relation)
Parameters
relation
Type: String
Will prefix fields with the given relation, e.g. MyLookupField__r

getSObjectFieldList()

Implement this method to inform the base class of the common fields to be queried or listed by the base class methods
Signature
abstract List<Schema.SObjectField> getSObjectFieldList()

getSObjectFieldSetList()

Override this method to provide a list of Fieldsets that can optionally drive inclusion of additional fields in the base queries
Signature
public virtual List<Schema.FieldSet> getSObjectFieldSetList()

getSObjectName()

Returns the string representation of the SObject this selector represents
Signature
public String getSObjectName()

getSObjectType()

Implement this method to inform the base class of the SObject (custom or standard) to be queried
Signature
abstract Schema.SObjectType getSObjectType()

getSObjectType2()

Public access for the getSObjectType during Mock registration (adding public to the existing method broken base class API backwards compatibility)
Signature
public SObjectType getSObjectType2()

ignoreCRUD()

Set the selector to ignore CRUD security @return
Signature
public fflib_SObjectSelector ignoreCRUD()

includeFieldSetFields()

Set the selector to automatically include the FieldSet fields when building queries
Signature
public fflib_SObjectSelector includeFieldSetFields()

isEnforcingCRUD()

Returns True if this Selector is enforcing CRUD Security
Signature
public Boolean isEnforcingCRUD()

isEnforcingFLS()

Returns True if this Selector is enforcing FLS
Signature
public Boolean isEnforcingFLS()

isIncludeFieldSetFields()

Returns True if this Selector instance has been instructed by the caller to include Field Set fields
Signature
public Boolean isIncludeFieldSetFields()

newQueryFactory()

Returns a QueryFactory configured with the Selectors object, fields, fieldsets and default order by
Signature
public fflib_QueryFactory newQueryFactory()

newQueryFactory(includeSelectorFields)

Returns a QueryFactory configured with the Selectors object, fields, fieldsets and default order by
Signature
public fflib_QueryFactory newQueryFactory(Boolean includeSelectorFields)

newQueryFactory(assertCRUD, enforceFLS, includeSelectorFields)

Returns a QueryFactory configured with the Selectors object, fields, fieldsets and default order by CRUD and FLS read security will be checked if the corresponding inputs are true (overrides that defined in the selector).
Signature
public fflib_QueryFactory newQueryFactory(Boolean assertCRUD, Boolean enforceFLS, Boolean includeSelectorFields)

newQueryFactory(assertCRUD, enforceFLS, includeSelectorFields, dataAccess)

Signature
private fflib_QueryFactory newQueryFactory(Boolean assertCRUD, Boolean enforceFLS, Boolean includeSelectorFields, DataAccess dataAccess)

queryLocatorById(idSet)

Performs a SOQL query, - Selecting the fields described via getSObjectFieldsList and getSObjectFieldSetList (if included) - From the SObject described by getSObjectType - Where the Id's match those provided in the set - Ordered by the fields returned via getOrderBy
Signature
public virtual Database.QueryLocator queryLocatorById(Set<Id> idSet)
Returns
A QueryLocator (typically for use in a Batch Apex job)

selectSObjectsById(idSet)

Performs a SOQL query, - Selecting the fields described via getSObjectFieldsList and getSObjectFieldSetList (if included) - From the SObject described by getSObjectType - Where the Id's match those provided in the set - Ordered by the fields returned via getOrderBy
Signature
public virtual List<SObject> selectSObjectsById(Set<Id> idSet)
Returns
A list of SObject's

setDataAccess(access)

Signature
public fflib_SObjectSelector setDataAccess(DataAccess access)

setFieldListBuilder(fieldListBuilder)

Use this method to override the default FieldListBuilder (created on demand via getFieldListBuilder) with a custom one, warning, this will bypass anything getSObjectFieldList or getSObjectFieldSetList returns @depricated See newQueryFactory
Signature
public void setFieldListBuilder(fflib_StringBuilder.FieldListBuilder fieldListBuilder)

sObjectType()

Public access for the getSObjectType during Mock registration (adding public to the existing method broken base class API backwards compatibility1)
Signature
public SObjectType sObjectType()

unsortedSelectFields()

Signature
public fflib_SObjectSelector unsortedSelectFields()