[SalesForce] Knowledge – How to filter SOSL results by a SOQL and save on API calls

My organization frequently does work with SalesForce knowledge. And the recommended way to search Knowledge is either by the exact type of the article that you created in your instance or by the KnowledgeArticleVersion table, which contains the title and the published channels (internal/public/customer portal/app portal). The inherent problem with this is that you inevitably want to search the type of the article with SOSL, but you then need the channels as well – which can only be found in KnowledgeArticleVersion.

The only solution I can find to this is to:

  1. SOSL search on all types (one call, multiple objects merged)
  2. SOQL query on all articles from the category you did on KnowledgeArticleVersion (filter for internal only = true)
  3. Use some basic set merging on the two results and filter the ones that don't have the appropriate channel out.

Ideally, I'd like to be able to run one query on my specific type and intersect it with another table – effectively SOSL search fed to a SOQL filter. Is there a way to do this?

Best Answer

Yes, there is a way to do that:

FIND 'test' RETURNING KnowledgeArticleVersion(Id, Title, Summary WHERE PublishStatus='online' AND Language= 'your language')

You can add a condition on channel and data cateogry inside as it's done with Publish Status.