I want to query matching Accounts based NRIC Passport No AND Service Agent looking up to custom object Agent__c with a set of Ids (for bulkification) and i'm using:
- FIND '999999' IN ALL FIELDS RETURNING Account(Service_Agent__c, NRICPassport_No__c, Last_Policy_Date__c, LifeAsia_Client_Number__c WHERE Service_Agent__c IN ('a0M5D000000o42nUAA'))
On Apex transaction (trigger specifically), just returns empty list:
- List item
'(())'
But when I run on Anonymous Window, results brings up the expected sample records already on the database:
- System.debug([FIND '999999' IN ALL FIELDS RETURNING Account(Name, Service_Agent__c, NRICPassport_No__c, Last_Policy_Date__c, LifeAsia_Client_Number__c WHERE Service_Agent__c IN ('a0M5D000000o42nUAA'))]);
Result:
- 15:11:46:127 USER_DEBUG [1]|DEBUG|(( Account:{Name=Jeremy Lin, Service_Agent__c=a0M5D000000o42nUAA, NRICPassport_No__c=999999, LifeAsia_Client_Number__c=LA666666, Id=0015D00000QF7d8QAD, RecordTypeId=0127F0000009gh7QAA}, Account:{Name=Kobe Bryant, Service_Agent__c=a0M5D000000o42nUAA, NRICPassport_No__c=999999, LifeAsia_Client_Number__c=LA111111, Id=0015D00000Tu4ufQAB, RecordTypeId=0127F0000009gh7QAA}))
My code is inside Without Sharing inner class method so sharing should not affect it.
On Test Class and I set "SeeAllData=true" to use the sample user i'm using on the UI as the System.runAs() user, the results shows up and test classes are passing as expected.
Really weird behaviour that when that same user is navigating on the UI, the results are empty on the apex debugs.
By the way, Account is on Private Settings. So I believe it shouldn't matter since we are running on System context. Unless I'm missing something that SOSL doesn't honor WITHOUT SHARING.