Add queryWithBinds to Selector layer #481
Replies: 3 comments
-
It might be a way to make real unit-test (with mocking) for selector classes. Now we can't really make those tests without going to the database. |
Beta Was this translation helpful? Give feedback.
-
@MayTheSForceBeWithYou -- Hi Nathan -- hope all is well Can you elaborate a bit more with a couple of example use cases? i.e. pseudocode for how you'd like a feature like this to work?
|
Beta Was this translation helpful? Give feedback.
-
The SOQL Lib has @AuraEnabled
public static List<Account> getPartnerAccounts(String accountName) {
return AccountsSelector.query()
.byRecordType('Partner')
.whereAre(SOQL.Filter.name().contains(accountName)) // < == variable automatically binded
.with(Account.BillingCity, Account.BillingCountry)
.toList();
} public inherited sharing class AccountsSelector extends SOQL implements SOQL.Selector {
public static final String MOCK_ID = 'SOQL_Account';
public static SOQL_Account query() {
return new SOQL_Account();
}
private SOQL_Account() {
super(Account.SObjectType);
// default settings
with(Account.Id, Account.Name);
systemMode();
withoutSharing();
mockId(MOCK_ID);
}
public SOQL_Account byType(String type) {
whereAre(Filter.with(Account.Type).equal(type));
return this;
}
public SOQL_Account byIndustry(String industry) {
whereAre(Filter.with(Account.Industry).equal(industry));
return this;
}
public SOQL_Account byParentId(Id parentId) {
whereAre(Filter.with(Account.ParentId).equal(parentId));
return this;
}
public SOQL_Account byOwnerId(Id ownerId) {
whereAre(Filter.with(Account.OwnerId).equal(ownerId));
return this;
}
} |
Beta Was this translation helpful? Give feedback.
-
In Winter '24 release, Salesforce introduced the ability to make SOQL queries with bound parameters:
Dynamically Pass Bind Variables to a SOQL Query. Add this functionality to the fflib Selector layer.
Describe the solution you'd like
// TODO: A clear and concise description of what you want to happen.
Describe alternatives you've considered
// TODO: A clear and concise description of any alternative solutions or features you've considered.
Additional context
// TODO: Add any other context or screenshots about the feature request here.
Beta Was this translation helpful? Give feedback.
All reactions