+ Start a Discussion
Priyanka BardhanPriyanka Bardhan 

SOSL OR condition - searching set of ids

Hi,
Can anyone please help with OR condition in SOSL?
I am trying to find ids in Custom Object records. Below snippet I am trying in workbench. I tried with double quote also, but it didn't work. Please note ids contains hypen.

List<List<sObject>> instanceRecs = [FIND {'7675675670-6795-4621-817e-74a6b056556' OR '56524ab-eaaf-4eb2-bccf-85bfd565650'} IN ALL Fields Returning Instance__c];

Also, whether it is possible to search set of ids in SOSL?

Thanks,
Priyanka
Amit Chaudhary 8Amit Chaudhary 8
Please check below post to learn about SOSL
1) https://trailhead.salesforce.com/en/modules/apex_database/units/apex_database_sosl


This example shows how to run a SOSL query in Apex. This SOSL query combines two search terms by using the OR logical operator—it searches for Wingo or SFDC in any field. This example returns all the sample accounts because they each have a field containing one of the words. The SOSL search results are returned in a list of lists. Each list contains an array of the returned records. In this case, the list has two elements. At index 0, the list contains the array of accounts. At index 1, the list contains the array of contacts.
Execute this snippet in the Execute Anonymous window of the Developer Console. Next, inspect the debug log to verify that all records are returned.
List<List<sObject>> searchList = [FIND 'Wingo OR SFDC' IN ALL FIELDS 
                   RETURNING Account(Name),Contact(FirstName,LastName,Department)];
Account[] searchAccounts = (Account[])searchList[0];
Contact[] searchContacts = (Contact[])searchList[1];

System.debug('Found the following accounts.');
for (Account a : searchAccounts) {
    System.debug(a.Name);
}

System.debug('Found the following contacts.');
for (Contact c : searchContacts) {
    System.debug(c.LastName + ', ' + c.FirstName);
}

In your case try below code


List<List<sObject>> instanceRecs = [FIND '7675675670-6795-4621-817e-74a6b05655' OR 56524ab-eaaf-4eb2-bccf-85bfd565650' IN ALL Fields Returning Instance__c];

Let us know if this will work