diff --git a/force-app/repository/Query.cls b/force-app/repository/Query.cls index c37177b..07e68fa 100644 --- a/force-app/repository/Query.cls +++ b/force-app/repository/Query.cls @@ -202,7 +202,7 @@ public virtual class Query { public virtual override String toString() { if (this.operator == Query.Operator.NOT_LIKE) { // who knows why this is the format they wanted - return String.format(this.getOperator(), new List{ this.field }) + ' ' + this.predicate; + return String.format(this.getOperator(), new List{ this.field, this.predicate.toString() }); } return this.field + ' ' + this.getOperator() + ' ' + this.predicate; } @@ -243,7 +243,7 @@ public virtual class Query { returnVal = 'like'; } when NOT_LIKE { - returnVal = 'not {0} like'; + returnVal = '(not {0} like {1})'; } } return returnVal; diff --git a/force-app/repository/QueryTests.cls b/force-app/repository/QueryTests.cls index 1689996..635eb0a 100644 --- a/force-app/repository/QueryTests.cls +++ b/force-app/repository/QueryTests.cls @@ -121,7 +121,7 @@ private class QueryTests { Query notLike = Query.notLike(Account.Name, expectedName); - System.assertEquals('not Name like :bindVar0', notLike.toString()); + System.assertEquals('(not Name like :bindVar0)', notLike.toString()); System.assertEquals(expectedName, notLike.getBindVars().get('bindVar0')); } @@ -133,10 +133,25 @@ private class QueryTests { Query notLike = Query.notLike(Account.Name, values); - System.assertEquals('not Name like :bindVar0', notLike.toString()); + System.assertEquals('(not Name like :bindVar0)', notLike.toString()); System.assertEquals(values, notLike.getBindVars().get('bindVar0')); } + @IsTest + static void it_should_allow_multiple_not_like_statements() { + String someName = '%someName%'; + String otherName = '%otherName%'; + + Query multipleNotLike = Query.andQuery(new List { + Query.notLike(Account.Name, someName), + Query.notLike(Account.Name, otherName) + }); + + System.assertEquals('((not Name like :bindVar0) AND (not Name like :bindVar1))', multipleNotLike.toString()); + System.assertEquals(someName, multipleNotLike.getBindVars().get('bindVar0')); + System.assertEquals(otherName, multipleNotLike.getBindVars().get('bindVar1')); + } + @IsTest static void it_should_allow_parent_fields_for_filtering() { Query parentQuery = Query.equals(Group.DeveloperName, 'SOME_CONSTANT.DeveloperName')