Skip to content

Commit

Permalink
Added the ability to specify the condition on a queryfactory by using…
Browse files Browse the repository at this point in the history
… a 'ISearchCriteria'
  • Loading branch information
rob-baillie-ortoo committed Apr 28, 2022
1 parent d36342e commit e19d5ea
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,21 @@ public class fflib_QueryFactory { //No explicit sharing declaration - inherit fr
public Schema.SObjectType table {get; private set;}
@TestVisible
private Set<String> fields;
private String conditionExpression;
private String conditionExpression {
get {
if ( conditionCriteria != null && String.isNotBlank( conditionExpression ) ) {
throw new fflib_Application.DeveloperException( 'Both criteria and expression were set on the query factory : ' + conditionExpression + ' + ' + conditionCriteria );
}
else {
if ( conditionCriteria != null ) {
return conditionCriteria.toSOQL();
}
}
return conditionExpression;
}
set;
}
private ISearchCriteria conditionCriteria;
private Integer limitCount;
private Integer offsetCount;
private List<Ordering> order;
Expand Down Expand Up @@ -299,6 +313,15 @@ public class fflib_QueryFactory { //No explicit sharing declaration - inherit fr
this.conditionExpression = conditionExpression;
return this;
}

/**
* @param conditionExpression Sets the WHERE clause to the string provided by the given ISearchCriteria
**/
public fflib_QueryFactory setCondition(ISearchCriteria criteria){
this.conditionCriteria = criteria;
return this;
}

/**
* @returns the current value of the WHERE clause, if any, as set by {@link #setCondition}
**/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,6 @@ public inherited sharing class ortoo_DynamicSobjectSelector extends ortoo_Sobjec
@testVisible
private String generateSoqlByCriteria( ortoo_Criteria criteria )
{
return newQueryFactory().selectFields( fieldList ).setCondition( criteria.toSOQL() ).toSOQL();
return newQueryFactory().selectFields( fieldList ).setCondition( criteria ).toSOQL();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public abstract inherited sharing class ortoo_SobjectSelector extends fflib_Sobj

if ( countOfRecords > 0 )
{
fflib_QueryFactory queryFactory = newQueryFactory().setCondition( criteria.toSOQL() );
fflib_QueryFactory queryFactory = newQueryFactory().setCondition( criteria );

queryFactory.selectFields( searchConfiguration.getRequiredFields() );
queryFactory.setOffset( window.offset );
Expand Down

0 comments on commit e19d5ea

Please sign in to comment.