I'm currently experiencing a problem where a regular old [SELECT ...]
query returns results as expected, but a [FIND ...]
does not. I have produced a simplified case below:
@isTest
public class DownloadTest {
@isTest
static void canUseFind() {
String email = '[email protected]';
// Insert a new lead
Lead l = new Lead(LastName='Doe', Company='ABC Widgets', Email=email);
insert l;
// Can select a lead
List<Lead> leads = [SELECT Email, LastName FROM Lead];
System.debug('LEADS1: ' + leads);
System.assertEquals(1, leads.size());
List<List<SObject>> res = search.query('FIND \'' + email + '\' IN ALL FIELDS RETURNING Lead');
System.debug('LEADS2: ' + res);
System.assertEquals(1, res.get(0).size()); // Failure
}
}
The salient part of the debug output:
11:56:22.4 (531026273)|SOQL_EXECUTE_BEGIN|[19]|Aggregations:0|SELECT Email, LastName FROM Lead
11:56:22.4 (553387865)|SOQL_EXECUTE_END|[19]|Rows:1
11:56:22.4 (553670355)|VARIABLE_SCOPE_BEGIN|[19]|leads|List<Lead>|true|false
11:56:22.4 (553849627)|VARIABLE_ASSIGNMENT|[19]|leads|[{"Email":"[email protected]","LastName":"Doe","Id":"00Q8D000003lRxcUAE"}]|0x1060b27e
11:56:22.4 (553864941)|STATEMENT_EXECUTE|[20]
11:56:22.4 (554146833)|USER_DEBUG|[20]|DEBUG|LEADS1: (Lead:{[email protected], LastName=Doe, Id=00Q8D000003lRxcUAE})
11:56:22.4 (554160870)|STATEMENT_EXECUTE|[21]
11:56:22.4 (554302031)|STATEMENT_EXECUTE|[23]
11:56:22.4 (554816404)|SOSL_EXECUTE_BEGIN|[23]|FIND '[email protected]' IN ALL FIELDS RETURNING Lead
11:56:22.4 (571604203)|SOSL_EXECUTE_END|[23]|Rows:0
11:56:22.4 (571707160)|VARIABLE_SCOPE_BEGIN|[23]|res|List<List<SObject>>|true|false
11:56:22.4 (571851657)|VARIABLE_ASSIGNMENT|[23]|res|[[]]|0x2303567e
11:56:22.4 (571861545)|STATEMENT_EXECUTE|[24]
11:56:22.4 (571982014)|USER_DEBUG|[24]|DEBUG|LEADS2: (())
Per recommendations I've found elsewhere (e.x. here), I'm creating records within the test so as not to need isTest(SeeAllData=true)
.
I'm pretty confident I'm missing something that's going to be obvious to someone else. I've had this working anonymous Apex, so I know the concept works. Just not sure what I'm doing incorrectly here. Thanks folks!