0

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.

  • can you check that all the placeholder is correctly replaced in the trigger? – Santanu Boral Apr 15 at 7:06
  • yeah, my test classes are passing. it is when i invoke it from UI (logging as a regular user/ non-system admin profile) that the values on SOSL doesn't show up. But SOQL with same conditions/filters shows the records up. – Jefferson Fernandez Apr 15 at 7:08
  • So, from test classes you are getting empty list. Is that correct assumption? – Santanu Boral Apr 15 at 7:21
  • Test Class are showing values accurately through Test.setFixedSearchResults(), i mean there should be no problem with my code logic because I get my expected results. It is on the debug statements when I do the testing on the User Interfrace (creating a record using a regular user profile), etc – Jefferson Fernandez Apr 15 at 7:28
  • What is the total number of records in the database table? – Santanu Boral Apr 15 at 7:30
0

Found out that SOSL still honors the FLS. I thought Apex should be system context, but on the running user profile, i gave access to the fields being searched by the SOSL on apex, then the results appeared. No documentation indicating it on the SOSL/SOQL developer guide.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.