How do I get SOSL WITH HIGHLIGHT in Apex?

Is it possible to get the highlight field from a SOSL search within apex?

For example:

List<List<Contact>> results = [
  FIND {text} IN ALL FIELDS RETURNING Contact(Id, Name) WITH HIGHLIGHT
];

Is there a way to get the highlight field containing the <mark>text</mark> tags? For example:

contact.get('highlight.Name');

Or is this only available when executing SOSL using the API?

Answer

Unfortunately, it is available only in SOAP api and REST api as mentioned in the official documentation here in Supported APIs section:

The WITH HIGHLIGHT clause in SOSL is supported in SOAP API and REST
API.

Attribution
Source : Link , Question Author : fehays , Answer Author : kurunve

Leave a Comment