3

Query

enter image description here

Result

enter image description here

why SOSL-query is empty?

1 Answer 1

6

SOSL indexing lags behind record creation, possibly by up to a few minutes. You may simply need to wait for the record to be indexed before it can be searched. You definitely cannot find a record that was created in the current transaction, as search indexing is asynchronous. If it's been longer than ten minutes, you should probably contact support to see if there's a problem.

Example:

Account a = new Account(Name='123456');
insert a;
System.debug([SELECT Name FROM Account WHERE Name = '123456']); // 1 result
System.debug([FIND '123456' IN ALL FIELDS RETURNING Account(Name)]); // No results

Edit:

If you're hoping to use SOSL in a Unit Test, make sure you use Test.setFixedSearchResults in order to have your SOSL return the relevant records.

Account a = new Account(Name='123456');
insert a;
System.debug([SELECT Name FROM Account WHERE Name = '123456']); // 1 result
Test.setFixedSearchResults(new Id[] { a.Id });
System.debug([FIND '123456' IN ALL FIELDS RETURNING Account(Name)]); // 1 result

You can't use this outside of a unit test.

1
  • Interesting. @sfdcfox Jun 1, 2021 at 4:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .