0

Has anyone meet the problem that the SOSL query result does not as the expectation?

One of our customer met the problem that the search result is much less than what it should be, than I ran the query on Developer Console, which is:

List<Candidate__c> cms = [SELECT Candidate__c FROM cm__c WHERE cm__c = 'a0C9000000SjkPO' AND Status__c = 'New'];
List<Id> candidateIds = new List<Id> ();
for(Candidate__c cm : cms)
    candidateIds.add(cm.Candidate__c);
List<List<sObject>> results = [FIND 'quality' RETURNING Contact (Name WHERE Id IN :candidateIds)];

The simple query is just search the keyword "quality" in some specific contacts which has status as "New". For the case here all the contacts in query should contains the keyword in one or more of their fields, but the result only returns 2 of them currently.

Does anyone knows any Salesforce explanation of this kind of situation? Thanks in advance for all your help.

0

According to the SOSL query written, result will return contact which have any fields filled with exact string "quality". Perhaps you are looking for finding all contact which have the keyword "quality" in their fields values.

There you should use wildcards like:

// Return all records contain "quality" anywhere in fields     
List<List<sObject>> results = [FIND '*quality*' RETURNING Contact (Name WHERE Id IN :candidateIds)];


// Return all records contain "quality" a prefix in fields     
List<List<sObject>> results = [FIND 'quality*' RETURNING Contact (Name WHERE Id IN :candidateIds)];

Reference: SOQL and SOSL

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.