Skip to content
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

Update fflib_QueryFactory.cls #34

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions fflib/src/classes/fflib_QueryFactory.cls
Original file line number Diff line number Diff line change
Expand Up @@ -472,35 +472,46 @@ public class fflib_QueryFactory { //No explicit sharing declaration - inherit fr
* Check to see if subqueries queries need to be added after the field list.
**/
public String toSOQL(){
String result = 'SELECT ';
StringBuilder query = new StringBuilder('SELECT ');
//if no fields have been added, just add the Id field so that the query or subquery will not just fail
if (fields.size() == 0){
if (enforceFLS) fflib_SecurityUtils.checkFieldIsReadable(table, 'Id');
result += 'Id ';
query.add('Id ');
}else{
List<QueryField> fieldsToQuery = new List<QueryField>(fields);
fieldsToQuery.sort(); //delegates to QueryFilter's comparable implementation
for(QueryField field:fieldsToQuery){
result += field + ', ';
query.add(field);
query.add(', ');
}
}
if(subselectQueryMap != null && !subselectQueryMap.isEmpty()){
for (fflib_QueryFactory childRow : subselectQueryMap.values()){
result += ' (' + childRow.toSOQL() + '), ';
query.add(' (');
query.add(childRow.toSOQL());
query.add('), ');
}
}
result = result.substring(0,result.length()-2) + ' FROM ' + (relationship != null ? relationship.getRelationshipName() : table.getDescribe().getName());
if(conditionExpression != null)
result += ' WHERE '+conditionExpression;
query.add(' WHERE ');
query.add(conditionExpression);

if(order.size() > 0){
result += ' ORDER BY ';
for(Ordering o:order)
result += o.toSOQL() +', ';
result = result.substring(0,result.length()-2);
query.add(' ORDER BY ');
List<String> OrderArg = new List<String>();
for(Ordering o:order) {
OrderArg.add(o.toSOQL());
OrderArg.add(', ');
}
OrderArg.remove(OrderArg.size()-1);
query.add(OrderArg);
}

if(limitCount != null)
if(limitCount != null) {
query.add(
}

result += ' LIMIT '+limitCount;
return result;
}
Expand Down Expand Up @@ -654,4 +665,4 @@ public class fflib_QueryFactory { //No explicit sharing declaration - inherit fr
public class InvalidFieldSetException extends Exception{}
public class NonReferenceFieldException extends Exception{}
public class InvalidSubqueryRelationshipException extends Exception{}
}
}