diff --git a/src/classes/Query.cls b/src/classes/Query.cls index 22db5c0..400cb16 100644 --- a/src/classes/Query.cls +++ b/src/classes/Query.cls @@ -1585,8 +1585,9 @@ public class Query { } public Integer countQuery() { - count(''); + isCountQuery = true; String queryString = formQueryString(); + isCountQuery = false; return Database.countQuery(queryString); } @@ -1620,7 +1621,8 @@ public class Query { private ParentFieldSetting parentFieldSetting; private List conditions = new List(); - private static final Integer maxArgSize = 20; + @testVisible + private static final Integer maxArgSize = 60; private Integer finalConditionArgsIdx = 0; private List conditionArgs = new List(); private List finalConditionArgs = new List(); @@ -1644,6 +1646,46 @@ public class Query { private Object conditionArgs17; private Object conditionArgs18; private Object conditionArgs19; + private Object conditionArgs20; + private Object conditionArgs21; + private Object conditionArgs22; + private Object conditionArgs23; + private Object conditionArgs24; + private Object conditionArgs25; + private Object conditionArgs26; + private Object conditionArgs27; + private Object conditionArgs28; + private Object conditionArgs29; + private Object conditionArgs30; + private Object conditionArgs31; + private Object conditionArgs32; + private Object conditionArgs33; + private Object conditionArgs34; + private Object conditionArgs35; + private Object conditionArgs36; + private Object conditionArgs37; + private Object conditionArgs38; + private Object conditionArgs39; + private Object conditionArgs40; + private Object conditionArgs41; + private Object conditionArgs42; + private Object conditionArgs43; + private Object conditionArgs44; + private Object conditionArgs45; + private Object conditionArgs46; + private Object conditionArgs47; + private Object conditionArgs48; + private Object conditionArgs49; + private Object conditionArgs50; + private Object conditionArgs51; + private Object conditionArgs52; + private Object conditionArgs53; + private Object conditionArgs54; + private Object conditionArgs55; + private Object conditionArgs56; + private Object conditionArgs57; + private Object conditionArgs58; + private Object conditionArgs59; private String conditionOperator = 'AND'; private String optionalClause = ''; @@ -1741,6 +1783,7 @@ public class Query { private String objectName; private Schema.SObjectType objectType; private Map childRelationships; + private Boolean isCountQuery = false; private Query addAllFields() { // Get all the fields @@ -2016,6 +2059,86 @@ public class Query { conditionArgs18 = arg; } else if (idx == 19) { conditionArgs19 = arg; + } else if (idx == 20) { + conditionArgs20 = arg; + } else if (idx == 21) { + conditionArgs21 = arg; + } else if (idx == 22) { + conditionArgs22 = arg; + } else if (idx == 23) { + conditionArgs23 = arg; + } else if (idx == 24) { + conditionArgs24 = arg; + } else if (idx == 25) { + conditionArgs25 = arg; + } else if (idx == 26) { + conditionArgs26 = arg; + } else if (idx == 27) { + conditionArgs27 = arg; + } else if (idx == 28) { + conditionArgs28 = arg; + } else if (idx == 29) { + conditionArgs29 = arg; + } else if (idx == 30) { + conditionArgs30 = arg; + } else if (idx == 31) { + conditionArgs31 = arg; + } else if (idx == 32) { + conditionArgs32 = arg; + } else if (idx == 33) { + conditionArgs33 = arg; + } else if (idx == 34) { + conditionArgs34 = arg; + } else if (idx == 35) { + conditionArgs35 = arg; + } else if (idx == 36) { + conditionArgs36 = arg; + } else if (idx == 37) { + conditionArgs37 = arg; + } else if (idx == 38) { + conditionArgs38 = arg; + } else if (idx == 39) { + conditionArgs39 = arg; + } else if (idx == 40) { + conditionArgs40 = arg; + } else if (idx == 41) { + conditionArgs41 = arg; + } else if (idx == 42) { + conditionArgs42 = arg; + } else if (idx == 43) { + conditionArgs43 = arg; + } else if (idx == 44) { + conditionArgs44 = arg; + } else if (idx == 45) { + conditionArgs45 = arg; + } else if (idx == 46) { + conditionArgs46 = arg; + } else if (idx == 47) { + conditionArgs47 = arg; + } else if (idx == 48) { + conditionArgs48 = arg; + } else if (idx == 49) { + conditionArgs49 = arg; + } else if (idx == 50) { + conditionArgs50 = arg; + } else if (idx == 51) { + conditionArgs51 = arg; + } else if (idx == 52) { + conditionArgs52 = arg; + } else if (idx == 53) { + conditionArgs53 = arg; + } else if (idx == 54) { + conditionArgs54 = arg; + } else if (idx == 55) { + conditionArgs55 = arg; + } else if (idx == 56) { + conditionArgs56 = arg; + } else if (idx == 57) { + conditionArgs57 = arg; + } else if (idx == 58) { + conditionArgs58 = arg; + } else if (idx == 59) { + conditionArgs59 = arg; } } @@ -2038,12 +2161,16 @@ public class Query { finalConditionArgsIdx = 0; String query = 'SELECT '; + + if (this.isCountQuery) { + query += 'COUNT()'; + } else { + query += formFieldString(); - query += formFieldString(); - - if (!functionFieldList.isEmpty()) { - query += ' ' + formAggregateString(); - } + if (!functionFieldList.isEmpty()) { + query += ' ' + formAggregateString(); + } + } query += ' FROM ' + objectName; @@ -2589,4 +2716,4 @@ public class Query { private String conditionString; private List args; } -} +} \ No newline at end of file diff --git a/src/classes/Query.cls-meta.xml b/src/classes/Query.cls-meta.xml index db9bf8c..7a51829 100644 --- a/src/classes/Query.cls-meta.xml +++ b/src/classes/Query.cls-meta.xml @@ -1,5 +1,5 @@ - 48.0 + 58.0 Active diff --git a/src/classes/QueryTest.cls b/src/classes/QueryTest.cls index 6bad447..065d3b0 100644 --- a/src/classes/QueryTest.cls +++ b/src/classes/QueryTest.cls @@ -1119,6 +1119,7 @@ public class QueryTest { System.assertEquals(4, new Query('Account').countQuery()); System.assertEquals(2, new Query('Account').addConditionEq('Rating', '1').countQuery()); + System.assertEquals(2, new Query('Account').selectAllFields('Account').addConditionEq('Rating', '1').countQuery()); } @isTest @@ -1350,6 +1351,35 @@ public class QueryTest { System.assert(c != null); } + @isTest + static void largeWhereClauseTest() { + Integer maxWhereConditions = Query.maxArgSize; + + Query query = new Query('Account'); + for (Integer i = 0; i < maxWhereConditions; i++) { + query.addConditionEq('Name', 'Name' + i); + } + + Exception excptn; + + try { + query.run(); + } catch (Exception ex) { + excptn = ex; + } + + Assert.areEqual(null, excptn); + + Test.startTest(); + try { + query.addConditionEq('Name', 'Name' + maxWhereConditions); + query.run(); + } catch (Exception qex) { + Assert.isNotNull(qex); + //Assert.areEqual('The number of arguments exceeds the limit', qex.getMessage()); + } + Test.stopTest(); + } static void createData() { Account acc = new Account(); acc.Name = 'ABC Ltd'; @@ -1400,4 +1430,4 @@ public class QueryTest { System.assertEquals(task.Subject, 'New Task'); } -} +} \ No newline at end of file diff --git a/src/classes/QueryTest.cls-meta.xml b/src/classes/QueryTest.cls-meta.xml index db9bf8c..7a51829 100644 --- a/src/classes/QueryTest.cls-meta.xml +++ b/src/classes/QueryTest.cls-meta.xml @@ -1,5 +1,5 @@ - 48.0 + 58.0 Active