• Jill Guidry
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Should SOSL searches return child Contact records of Accounts that match the search criteria when returning only Contacts?

Let's say you have an Account and Contact records represented by the following code:
Account smithServices;
Contact jane;
Contact mary;
Contact michael;

smithServices = new Account(Name = 'Smith Services');
insert smithServices;

jane = new Contact(FirstName = 'Jane', LastName = 'Ada', Account = smithServices);
mary = new Contact(FirstName = 'Mary', LastName = 'Smith');
michael = new Contact(FirstName = 'Michael', LastName = 'Smith');
insert new List<Contact>{jane, mary, michael};
Then perform the following SOSL search returning only Contact records:
List<List<SObject>> searchList = [FIND 'smith' IN NAME FIELDS RETURNING Contact(Name)];

for (SObject contact : searchList[0]) {
    System.debug(contact);
}
The Contact records returned from the SOSL search are:
Contact:{Name=Michael Smith}
Contact:{Name=Mary Smith}
Contact:{Name=Jane Ada}
I would expect the 'Jane Ada' Contact to not be in the results because that record doesn't include a name field that matches the search criteria.  It looks like it is included in the search results because the parent Account record's Name field matches the search criteria.  Is this expected behavor?


 
  • February 26, 2019
  • Like
  • 2