Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Added support for parent field filtering and including children queries

Pre-release
Pre-release
Compare
Choose a tag to compare
@jongpie jongpie released this 09 Jun 19:45
· 9 commits to master since this release

New Features & Enhancements

  • SObjectRepository.cls now uses QueryFilter.cls to handle filtering on fields from the base object, parent object and grandparent objects - the constructor used for QueryFilter.cls determines the type of filter
    Sample code for a filter to get accounts created by active users

    public class AccountRepository extends SObjectRepository {
        public AccountRepository() {
            // When only an SObject type is provided, all fields for the SObject are included in your queries
            super(Schema.Account.SObjectType);
        }
    
        public List<Account> getAccountsCreatedToday() {
            return (List<Account>)this.Query
                // Create an instance of QueryFilter to apply any filters to the query
                .filterBy(new QueryFilter(Schema.Account.Status, QueryOperator.EQUALS, QueryDateLiteral.TODAY))
                .getQueryResults();
        }
    }
    
  • Children queries can now be included in your queries generated by SObjectRepository.cls.

    Sample code showing a method that could be added to AccountRepository (not included in the repository):

    public class AccountRepository extends SObjectRepository {
        public AccountRepository() {
            // When only an SObject type is provided, all fields for the SObject are included in your queries
            super(Schema.Account.SObjectType);
        }
    
        public List<Account> getAccountsCreatedToday() {
            return (List<Account>)this.Query
                // Create an instance of QueryFilter to apply any filters to the query
                .filterBy(new QueryFilter(Schema.Account.Status, QueryOperator.EQUALS, QueryDateLiteral.TODAY))
                .getQueryResults();
        }
    
        public Account getAccountAndContactsWithEmails(Id accountId) {
            return (Account)this.Query
                .filterBy(new QueryFilter(Schema.Account.Id, QueryOperator.EQUALS, accountId))
                .includeChildrenRecords(
                    // Provide the child object's field that relates it to the parent object
                    Schema.Contact.AccountId,
                    // Filters for the children records can also be included
                    new ContactRepository().filterBy(new QueryFilter(Schema.Contact.Email, QueryOperator.NOT_EQUAL_TO, null))
                )
                .getFirstQueryResult();
        }
    }
    

Declarative/Configuration Changes

  • Logging is now enabled by default (via the custom setting NebulaLoggerSettings__c)
  • A custom app (cleverly called 'Nebula') has been added - it includes 1 tab for the NebulaLog__c object
  • Updated some field descriptions & help text on the various custom settings

Refactoring (Could Impact Existing Code)

  • SObjectRecordTypes.cls now uses QueryBuilder.cls for its query generation
  • QueryBuilder.whereField() method has been replaced by QueryBuilder.filterBy() - it expects either a single instance or a list of QueryFilter.cls
  • SObjectRepository.queryFactory is now SObjectRepository.Query
  • Miscellaneous cleanup - variable name standardisation, whitespace, etc
  • Removed the method ISObjectRepository.getCreatedSinceTimeValue
  • Delete CollectionUtils.cls
  • TestingUtils.setReadOnlyField() has been refactored to allow any object type as a value & to prevent duplicating fields on the returned SObject