4 Commits
Author SHA1 Message Date
github-actions 27d903678c Update package version to 0.10.0.NEXT
Create Release / release (push) Canceled after 0s
2026-08-05 08:36:21 +00:00
94129a9791 Override getRecordsWithNotBlankFieldValues for non-String fields (#90)
* Override getRecordsWithNotBlankFieldValues in fflib_SObjects2

The base fflib_SObjects implementation casts every value to String, which
throws a TypeException on Date/Datetime/Number/Lookup fields. This override
generalises the check to "any non-null value, and for Strings also non-blank"
so the helper works for every field type.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* Update fflib_SObjects2.cls

Rename method to getRecordsWithNonBlankFieldValues

* Update fflib_SObjects2Test.cls

Rename method to getRecordsWithNonBlankFieldValues

* Update fflib_SObjects2.cls

Rename variable

Co-authored-by: Robin Weymans <robin.weymans@mylighthouse.com>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-authored-by: William Velzeboer <6429417+wimvelzeboer@users.noreply.github.com>
2026-08-05 09:23:06 +01:00
github-actions 368978bf20 Update package version to 0.10.0.NEXT 2026-04-13 14:46:02 +00:00
William Velzeboerandgithub-actions 9716a88489 Generic Selector class (#86)
* Generic Selector class

usage
```
List<SObject> records =
    fflib_SObjectsSelector.newElevatedInstance(
            Schema.Account.SObjectType,
            new List<SObjectType>{ Schema.Account.Id, Schema.Account.Name }
    )
        .selectById(idSet);
```

* New package version 0.9.0-1-feature/genericSelector created

---------

Co-authored-by: github-actions <github-actions@github.com>
2026-04-13 15:45:27 +01:00
7 changed files with 293 additions and 9 deletions
+8 -2
View File
@@ -26,7 +26,13 @@ jobs:
run: npm install @salesforce/cli --global run: npm install @salesforce/cli --global
- name: Authorize with the dev hub - name: Authorize with the dev hub
run: echo "${{ secrets.SFDX_AUTH_URL }}" | sf org login sfdx-url --alias SFDX-ENV --set-default-dev-hub --sfdx-url-stdin env:
SFDX_AUTH_URL: ${{ secrets.SFDX_AUTH_URL }}
run: |
echo "$SFDX_AUTH_URL" | wc -c
echo "${{ secrets.SFDX_AUTH_URL }}" | wc -c
echo "$Env:SFDX_AUTH_URL" | wc -c
echo "${{ secrets.SFDX_AUTH_URL }}" | sf org login sfdx-url --alias SFDX-ENV --set-default-dev-hub --sfdx-url-stdin
- name: Setup the config parameters needed - name: Setup the config parameters needed
run: | run: |
@@ -82,4 +88,4 @@ jobs:
- name: Push changes to GIT - name: Push changes to GIT
run: | run: |
git push git push
+4 -2
View File
@@ -10,10 +10,10 @@ This extension package is dependent on the following packages:
The package is available as an Unlocked Managed Package (2GP) with package ID `0HoJ8000000KyjfKAC`. The package is available as an Unlocked Managed Package (2GP) with package ID `0HoJ8000000KyjfKAC`.
Either clone the repository and import the package manually, use the [Package Installation URL](https://login.salesforce.com/packaging/installPackage.apexp?p0=04tJ8000000kaL4IAI) Either clone the repository and import the package manually, use the [Package Installation URL](https://login.salesforce.com/packaging/installPackage.apexp?p0=04tJ8000000kaPHIAY)
or execute the following SFDX CLI command in your terminal: or execute the following SFDX CLI command in your terminal:
```bash ```bash
sf package install --package 04tJ8000000kaL4IAI --wait=10 --target-org $YOUR_ORG_ALIAS sf package install --package 04tJ8000000kaPHIAY --wait=10 --target-org $YOUR_ORG_ALIAS
``` ```
_Replace `$YOUR_ORG_ALIAS` with the alias of your target org_ _Replace `$YOUR_ORG_ALIAS` with the alias of your target org_
@@ -125,3 +125,5 @@ Thank you for your donations!
|-----------------------------------------------|--------------------|--------------------------------| |-----------------------------------------------|--------------------|--------------------------------|
| 0.1.0-2 | 04tJ8000000kaKVIAY | Created on 26/03/2026 20:07:07 || 0.7.0.1 | 04tJ8000000kaKzIAI | Created on 30/03/2026 13:49:28 | | 0.1.0-2 | 04tJ8000000kaKVIAY | Created on 26/03/2026 20:07:07 || 0.7.0.1 | 04tJ8000000kaKzIAI | Created on 30/03/2026 13:49:28 |
| 0.8.0.1 | 04tJ8000000kaL4IAI | Created on 31/03/2026 11:51:16 | | 0.8.0.1 | 04tJ8000000kaL4IAI | Created on 31/03/2026 11:51:16 |
| 0.9.0.1 | 04tJ8000000kaPHIAY | Created on 13/04/2026 14:46:02 |
| 0.9.0.1 | 04tJ8000000kaPHIAY | Created on 05/08/2026 08:36:21 |
+4 -3
View File
@@ -1,8 +1,8 @@
{ {
"packageDirectories": [ "packageDirectories": [
{ {
"versionName": "ver 0.9", "versionName": "ver 0.10",
"versionNumber": "0.9.0.NEXT", "versionNumber": "0.10.0.NEXT",
"path": "sfdx-source", "path": "sfdx-source",
"default": true, "default": true,
"package": "fflibApexExtensions", "package": "fflibApexExtensions",
@@ -16,6 +16,7 @@
"packageAliases": { "packageAliases": {
"fflibApexExtensions": "0HoJ8000000KyjfKAC", "fflibApexExtensions": "0HoJ8000000KyjfKAC",
"fflibApexExtensions@0.7.0-1": "04tJ8000000kaKzIAI", "fflibApexExtensions@0.7.0-1": "04tJ8000000kaKzIAI",
"fflibApexExtensions@0.8.0-1-apiUpgrade": "04tJ8000000kaL4IAI" "fflibApexExtensions@0.8.0-1-apiUpgrade": "04tJ8000000kaL4IAI",
"fflibApexExtensions@0.9.0-1-feature/genericSelector": "04tJ8000000kaPHIAY"
} }
} }
@@ -1078,6 +1078,29 @@ public virtual class fflib_SObjects2
return getRecordsNotIn(sObjectField, new Set<String>{ value }); return getRecordsNotIn(sObjectField, new Set<String>{ value });
} }
/**
* Overrides the fflib_SObjects base implementation, which casts every value to `String` and
* uses `String.isNotBlank` — that throws a TypeException on Date / Datetime / Number / Lookup
* fields. This override generalises to "any non-null value, and for Strings also non-blank",
* so the helper works for every field type.
*
* @param field The field to check.
*
* @return The records whose value for `field` is non-null (and, for Strings, non-blank).
*/
protected override List<SObject> getRecordsWithNonBlankFieldValues(Schema.SObjectField sObjectField)
{
List<SObject> result = new List<SObject>();
for (SObject record : getRecords())
{
Object value = record.get(sObjectField);
if (value == null) continue;
if (value instanceof String && String.isBlank((String) value)) continue;
result.add(record);
}
return result;
}
@TestVisible @TestVisible
protected virtual List<SObject> getRecordsNotIn(Schema.SObjectField sObjectField, Set<String> values) protected virtual List<SObject> getRecordsNotIn(Schema.SObjectField sObjectField, Set<String> values)
{ {
@@ -1455,4 +1478,4 @@ public virtual class fflib_SObjects2
} }
public class DeveloperException extends Exception { } public class DeveloperException extends Exception { }
} }
@@ -0,0 +1,209 @@
/**
* File Name: fflib_SObjectsSelector
*
* Generic SObject selector class
*
* @author architect ir. Wilhelmus G.J. Velzeboer
*
* Copyright (c), W.G.J. Velzeboer,
* 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 author 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 author 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.
*/
public with sharing class fflib_SObjectsSelector
extends fflib_SObjectSelector {
/**
* The current implementation type of the service
*/
private static System.Type implementationType = fflib_SObjectsSelector.class;
/**
* The implementation replacement for the service,
*/
private static fflib_SObjectsSelector implementationReplacement;
/**
* The list of field that should be retrieved with each query
*/
private List<Schema.SObjectField> sObjectFields { get; set; }
/**
* Holds the SObjectType of the records to query
*/
private Schema.SObjectType sObjectType { get; set; }
/**
* Runs the query in System Mode, disabling FLS, CRUD & sharing rules
*
* @param sObjectType The SObjectType of the records to query
* @param sObjectFields a set of SObjectFields to get each time a Quote records is queried
*
* @return New instance of the selector
*/
public static fflib_SObjectsSelector newElevatedInstance(SObjectType sObjectType, Set<SObjectField> sObjectFields) {
fflib_SObjectsSelector selector =
(implementationReplacement == null) ? (fflib_SObjectsSelector) implementationType.newInstance() : implementationReplacement;
selector.setDataAccess(fflib_SObjectSelector.DataAccess.SYSTEM_MODE);
selector.setSObjectFields(sObjectFields);
selector.setSObjectType(sObjectType);
return selector;
}
/**
* Runs the query in System Mode, disabling FLS, CRUD & sharing rules
*
* @param sObjectType The SObjectType of the records to query
* @param sObjectFields a set of SObjectFields to get each time a Quote records is queried
*
* @return New instance of the selector
*/
public static fflib_SObjectsSelector newElevatedInstance(SObjectType sObjectType, Set<String> sObjectFields) {
fflib_SObjectsSelector selector =
(implementationReplacement == null) ? (fflib_SObjectsSelector) implementationType.newInstance() : implementationReplacement;
selector.setDataAccess(fflib_SObjectSelector.DataAccess.SYSTEM_MODE);
selector.setSObjectFields(sObjectType, sObjectFields);
selector.setSObjectType(sObjectType);
return selector;
}
/**
* Class constructor
* This should not be used directly by an application but only by fflib
*/
public fflib_SObjectsSelector() {
super();
}
/**
* The fields to always include in all queries
*
* @return Returns a list of default fields that are always queried
*/
public virtual List<Schema.SObjectField> getSObjectFieldList() {
return this.sObjectFields;
}
/**
* Defines the SObjectType for this selector
*
* @return the SObjectType of this selector
*/
public Schema.SObjectType getSObjectType() {
return this.sObjectType;
}
/**
* Replace the default implementation of the service
*
* @param systemType The System.Type of the replacement class
*/
public static void replaceWith(System.Type systemType) {
fflib_SObjectsSelector.implementationType = systemType;
}
/**
* Replace the default implementation of the service
*
* @param replacement A replacement instance
*
* @see fflib_SObjectsSelector
*/
public static void replaceWith(fflib_SObjectsSelector replacement) {
fflib_SObjectsSelector.implementationReplacement = replacement;
}
/**
* Queries records by their record Id
*
* @param idSet A set of record Id values
*
* @return A list of SObject records
*/
public virtual List<SObject> selectById(Set<Id> idSet) {
return Database.query(
newQueryFactory()
.setCondition('Id IN :idSet')
.toSOQL()
);
}
/**
* Queries SObject records by their record Id
*
* @param sObjectField The Id field to query
* @param ids A set of record Id values
*
* @return A list of SObject records
*/
public List<SObject> selectByIdField(SObjectField sObjectField, Set<Id> ids) {
return Database.query(
newQueryFactory()
.setCondition(sObjectField.getDescribe().getName() + ' IN :ids')
.toSOQL()
);
}
/**
* Sets the list of fields that are fetched on each query
*
* @param sObjectFields A set of SObjectFields from the SObjectType
*
* @return Returns an instance of itself to allow for method chaining
*/
public fflib_SObjectsSelector setSObjectFields(Set<SObjectField> sObjectFields) {
this.sObjectFields = new List<SObjectField>(sObjectFields);
return this;
}
/**
* Sets the list of fields that are fetched on each query
*
* @param sObjectType The SObjectType of the provided fields
* @param fieldNames A set of SObject field names
*
* @return Returns an instance of itself to allow for method chaining
*/
public fflib_SObjectsSelector setSObjectFields(SObjectType sObjectType, Set<String> fieldNames) {
Map<String, SObjectField> sObjectFieldsByName = sObjectType.getDescribe().fields.getMap();
Set<SObjectField> sObjectFields = new Set<SObjectField>();
for (String fieldName : fieldNames) {
if (sObjectFieldsByName.containsKey(fieldName) == false) continue;
sObjectFields.add(sObjectFieldsByName.get(fieldName));
}
setSObjectFields(sObjectFields);
return this;
}
/**
* Sets the SObjectType of the records to query
*
* @param sObjectType The SObjectType of the records to query
*
* @return Returns an instance of itself to allow for method chaining
*/
public fflib_SObjectsSelector setSObjectType(SObjectType sObjectType) {
this.sObjectType = sObjectType;
return this;
}
}
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>66.0</apiVersion>
<status>Active</status>
</ApexClass>
@@ -679,6 +679,30 @@ private class fflib_SObjects2Test
System.Assert.areEqual(3, domain.selectWithShippingCountry().size()); System.Assert.areEqual(3, domain.selectWithShippingCountry().size());
} }
@IsTest
static void itShouldReturnRecordsWithNonNullNumericField()
{
DomainAccounts domain = generateDomain();
System.Assert.areEqual(4, domain.selectWithAnnualRevenue().size());
}
@IsTest
static void itShouldReturnRecordsWithNonNullDatetimeField()
{
Datetime now = Datetime.now();
DomainAccounts domain = new DomainAccounts(
new List<Account>
{
(Account) fflib_MockSObjectUtil.addFieldValue(new Account(Name = 'A'), Account.CreatedDate, now),
(Account) fflib_MockSObjectUtil.addFieldValue(new Account(Name = 'B'), Account.CreatedDate, now),
new Account(Name = 'C')
}
);
System.Assert.areEqual(2, domain.selectWithCreatedDate().size());
}
@IsTest @IsTest
static void itShouldReturnRecordsWithAllFieldValues() static void itShouldReturnRecordsWithAllFieldValues()
{ {
@@ -845,11 +869,25 @@ private class fflib_SObjects2Test
public List<Account> selectWithShippingCountry() public List<Account> selectWithShippingCountry()
{ {
return getRecordsWithNotBlankFieldValues( return getRecordsWithNonBlankFieldValues(
Schema.Account.ShippingCountry Schema.Account.ShippingCountry
); );
} }
public List<Account> selectWithAnnualRevenue()
{
return getRecordsWithNonBlankFieldValues(
Schema.Account.AnnualRevenue
);
}
public List<Account> selectWithCreatedDate()
{
return getRecordsWithNonBlankFieldValues(
Schema.Account.CreatedDate
);
}
public List<Account> selectWithEmptyRecord() public List<Account> selectWithEmptyRecord()
{ {
return getRecordsWithAllBlankFieldValues( return getRecordsWithAllBlankFieldValues(