-
Notifications
You must be signed in to change notification settings - Fork 519
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
criteria factory suggestion #393
criteria factory suggestion #393
Conversation
@baksale I like that this criteria/condition factory is a small class and resolves this long open issue. |
Thanks for the feedback @wimvelzeboer fflib_Criteria looks interesting and much more solid.
I would suggest to split it into 2 or even 3 classes:
Evaluator class could contain a reference to Criteria class to do the evaluation of the records in runtime. I did some load testing:
Two things I could not understand:
fflib_CriteriaFactory alternatives for this: cf().isNotLike(Contact.LastName, 'A%') // could not find analogue in fflib_Criteria cf()
.configureForReferenceField(Opportunity.AccountId) //similar to fflib_QueryFactory approach
.greaterThan(Account.NumberOfEmployees, 1000)
.equalsTo(Account.BillingCountry, 'USA') We like fflib_QueryFactory but criteria build capability is missing and badly required there. Do you think we can incorporate fflib_CriteriaFactory or fflib_Criteria into the main codebase? Happy to incorporate any feedback if it is going to be useful. |
Could you provide any hints to move this forward? This is the example from the PR description: String criteriaAsString =
'IsWon = true AND Amount > 100000 AND' +
' ((Account.NumberOfEmployees > 1000 AND Account.BillingCountry = \'USA\') OR (Owner.Title = \'CEO\' AND Owner.Country = \'USA\'))';
fflib_CriteriaFactory bigUsCompanies = new fflib_CriteriaFactory()
.configureForReferenceField(Opportunity.AccountId)
.greaterThan(Account.NumberOfEmployees, 1000)
.equalsTo(Account.BillingCountry, 'USA');
fflib_CriteriaFactory ownerInUs = new fflib_CriteriaFactory()
.configureForReferenceField(Opportunity.OwnerId)
.equalsTo(User.Title, 'CEO')
.equalsTo(User.Country, 'USA');
fflib_CriteriaFactory cb = new fflib_CriteriaFactory()
.equalsTo(Opportunity.IsWon, true)
.greaterThan(Opportunity.Amount, 100000)
.composite(
new fflib_CriteriaFactory()
.composite(bigUsCompanies)
.withOr()
.composite(ownerInUs));
System.assertEquals(criteriaAsString, cb.toCriteria()); I need some guidance how to move this forward. I saw in many other similar PRs/Issues you mentioned that you put decisions on hold as the strategy is not clear. |
…ry#setCondition() method
…ry#setCondition() method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Supports all Comparison Operators
- Compile Time validation of the Field Names used in SOQL Criteria
- Dynamic SOQL Criteria based on User input
- Bind Variables
- Date Functions support
- Runtime Exception if criteria size breaks the 4000 characters limit
See #483 |
This change is
Hi guys, please take a look at the suggestion for Criteria Factory.
If you like the idea, I will add security checks and bind variables support.
Any other feedback is also welcome.
This is related to #292
More details can be found here