diff --git a/force-app/main/default/classes/SOSL.cls b/force-app/main/default/classes/SOSL.cls index f313bcf..bda58b3 100644 --- a/force-app/main/default/classes/SOSL.cls +++ b/force-app/main/default/classes/SOSL.cls @@ -121,9 +121,7 @@ public inherited sharing class SOSL implements ISearchable { IFilter isTrue(); IFilter isFalse(); IFilter equal(Object value); - IFilter equal(String value); IFilter notEqual(Object value); - IFilter notEqual(String value); IFilter lessThan(Object value); IFilter greaterThan(Object value); IFilter lessOrEqual(Object value); @@ -963,18 +961,10 @@ public inherited sharing class SOSL implements ISearchable { return set('=', value); } - public IFilter equal(String value) { - return set('=', quote(value)); - } - public IFilter notEqual(Object value) { return set('!=', value); } - public IFilter notEqual(String value) { - return set('!=', quote(value)); - } - public IFilter lessThan(Object value) { return set('<', value); } @@ -992,7 +982,7 @@ public inherited sharing class SOSL implements ISearchable { } public IFilter containsSome(Iterable values) { - return set('LIKE', '(\'' + String.join(values, '\'') + '\')'); + return set('LIKE', values); } public IFilter contains(String value) { @@ -1008,7 +998,7 @@ public inherited sharing class SOSL implements ISearchable { } public IFilter contains(String prefix, String value, String suffix) { - return set('LIKE', quote(prefix + formattedString(value) + suffix)); + return set('LIKE', prefix + formattedString(value) + suffix); } private String formattedString(String value) { @@ -1052,8 +1042,8 @@ public inherited sharing class SOSL implements ISearchable { } private IFilter set(String comperator, Object value) { - this.value = value; this.comperator = comperator; + this.value = value; return this; } diff --git a/force-app/main/default/classes/SOSL_Test.cls b/force-app/main/default/classes/SOSL_Test.cls index c48cc17..8cfbe4c 100644 --- a/force-app/main/default/classes/SOSL_Test.cls +++ b/force-app/main/default/classes/SOSL_Test.cls @@ -217,7 +217,8 @@ private class SOSL_Test { ); // Verify - Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE RecordType.DeveloperName = \'Partner\')', sosl.toString()); + Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE RecordType.DeveloperName = :binded0)', sosl.toString()); + Assert.areEqual('Partner', sosl.binding()[0]); } @IsTest @@ -232,7 +233,8 @@ private class SOSL_Test { ); // Verify - Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE Name = \'Test\')', sosl.toString()); + Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE Name = :binded0)', sosl.toString()); + Assert.areEqual('Test', sosl.binding()[0]); } @IsTest @@ -247,7 +249,8 @@ private class SOSL_Test { ); // Verify - Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE Industry = \'IT\')', sosl.toString()); + Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE Industry = :binded0)', sosl.toString()); + Assert.areEqual('IT', sosl.binding()[0]); } @IsTest @@ -262,7 +265,8 @@ private class SOSL_Test { ); // Verify - Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Contact(Id, Name WHERE Account.Industry = \'IT\')', sosl.toString()); + Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Contact(Id, Name WHERE Account.Industry = :binded0)', sosl.toString()); + Assert.areEqual('IT', sosl.binding()[0]); } @IsTest @@ -277,7 +281,8 @@ private class SOSL_Test { ); // Verify - Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE Industry = \'IT\')', sosl.toString()); + Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE Industry = :binded0)', sosl.toString()); + Assert.areEqual('IT', sosl.binding()[0]); } @IsTest @@ -292,7 +297,8 @@ private class SOSL_Test { ); // Verify - Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE Industry = null)', sosl.toString()); + Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE Industry = :binded0)', sosl.toString()); + Assert.areEqual(null, sosl.binding()[0]); } @IsTest @@ -352,7 +358,8 @@ private class SOSL_Test { ); // Verify - Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE NumberOfEmployees = 10)', sosl.toString()); + Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE NumberOfEmployees = :binded0)', sosl.toString()); + Assert.areEqual(10, sosl.binding()[0]); } @IsTest @@ -367,7 +374,8 @@ private class SOSL_Test { ); // Verify - Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE Name = \'My Account\')', sosl.toString()); + Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE Name = :binded0)', sosl.toString()); + Assert.areEqual('My Account', sosl.binding()[0]); } @IsTest @@ -382,7 +390,8 @@ private class SOSL_Test { ); // Verify - Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE NumberOfEmployees != 10)', sosl.toString()); + Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE NumberOfEmployees != :binded0)', sosl.toString()); + Assert.areEqual(10, sosl.binding()[0]); } @IsTest @@ -397,7 +406,8 @@ private class SOSL_Test { ); // Verify - Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE Name != \'My Account\')', sosl.toString()); + Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE Name != :binded0)', sosl.toString()); + Assert.areEqual('My Account', sosl.binding()[0]); } @IsTest @@ -462,17 +472,21 @@ private class SOSL_Test { @IsTest static void filterContainsSome() { + // Setup + List names = new List{ 'Test'}; + // Test SOSL sosl = SOSL.find(SEARCH_TEXT) .inAllFields() .returning( SOSL.Returning(Account.SObjectType) .with(Account.Id, Account.Name) - .whereAre(SOSL.Filter.with(Account.Name).containsSome(new List{ 'Test'})) + .whereAre(SOSL.Filter.with(Account.Name).containsSome(names)) ); // Verify - Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE Name LIKE (\'Test\'))', sosl.toString()); + Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE Name LIKE :binded0)', sosl.toString()); + Assert.areEqual(names, sosl.binding()[0]); } @IsTest @@ -487,7 +501,8 @@ private class SOSL_Test { ); // Verify - Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE Name LIKE \'%Test%\')', sosl.toString()); + Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE Name LIKE :binded0)', sosl.toString()); + Assert.areEqual('%Test%', sosl.binding()[0]); } @IsTest @@ -502,7 +517,8 @@ private class SOSL_Test { ); // Verify - Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE Name LIKE \'Test%\')', sosl.toString()); + Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE Name LIKE :binded0)', sosl.toString()); + Assert.areEqual('Test%', sosl.binding()[0]); } @IsTest @@ -517,11 +533,15 @@ private class SOSL_Test { ); // Verify - Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE Name LIKE \'%Test\')', sosl.toString()); + Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE Name LIKE :binded0)', sosl.toString()); + Assert.areEqual('%Test', sosl.binding()[0]); } @IsTest static void filterIsInListOfStrings() { + // Setup + List industries = new List{ 'IT' }; + // Test SOSL sosl = SOSL.find(SEARCH_TEXT) .inAllFields() @@ -532,7 +552,8 @@ private class SOSL_Test { ); // Verify - Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE Industry IN (\'IT\'))', sosl.toString()); + Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE Industry IN :binded0', sosl.toString()); + Assert.areEqual(industries, sosl.binding()[0]); } @IsTest @@ -676,7 +697,11 @@ private class SOSL_Test { ); // Verify - Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE (Name = \'MyAccount\' AND Industry = \'IT\'))', sosl.toString()); + Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE (Name = :binded0 AND Industry = :binded1))', sosl.toString()); + + List bindedValues = sosl.binding(); + Assert.areEqual('MyAccount', bindedValues[0]); + Assert.areEqual('IT', bindedValues[1]); } @IsTest @@ -695,7 +720,11 @@ private class SOSL_Test { ); // Verify - Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE (Name = \'MyAccount\' OR Industry = \'IT\'))', sosl.toString()); + Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE (Name = :binded0 OR Industry = :binded1))', sosl.toString()); + + List bindedValues = sosl.binding(); + Assert.areEqual('MyAccount', bindedValues[0]); + Assert.areEqual('IT', bindedValues[1]); } @IsTest @@ -718,7 +747,13 @@ private class SOSL_Test { ); // Verify - Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE (Name = \'MyAccount\' AND Industry = \'IT\' AND (NumberOfEmployees > 5 OR IsDeleted = false)))', sosl.toString()); + Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE (Name = :binded0 AND Industry = :binded1 AND (NumberOfEmployees > :binded2 OR IsDeleted = :binded3)))', sosl.toString()); + + List bindedValues = sosl.binding(); + Assert.areEqual('MyAccount', bindedValues[0]); + Assert.areEqual('IT', bindedValues[1]); + Assert.areEqual(5, bindedValues[2]); + Assert.areEqual(false, bindedValues[3]); } @IsTest