0

I have SOSL queries in my Apex which work well on Knoledge__kav object. When running test classes I receive the "you must specify a language where clause for knowledge articles in this API version" error. I note on reading https://developer.salesforce.com/docs/atlas.en-us.knowledge_dev.meta/knowledge_dev/sforce_api_objects_knowledge__kav.htm That it states

"Querying or searching articles in SOSL require that you specify the Language field in the WHERE clause. The language must be the same for all article types.

Before API version 47.0, you must include the Language field to filter queries on Knowledge article versions. In API version 47.0 and later, you can filter queries on Knowledge article versions with or without Language depending on what you are querying."

As no error came up when running the logic prior to trying to test it in a test class I presumed no language clause was actually required. I only receive the error on running unit tests. Is it correct that a language is always required (even if in 51 version of the API)?

if I try to apply it via the following

articleSearchResults = [
            FIND :searchTerm
            IN ALL FIELDS
            RETURNING
            Knowledge__kav(Id WHERE Language=:UserInfo.getLanguage())
        ]; 

I receive an error as follows "Implementation restriction: When searching the Knowledge__kav object, you must include a filter on Language = [language ISO code] as a top-level AND condition."

Is it correct that the Language field is required? Its confusing when it mentions API v.47.

How would I apply this in a SOSL query? I was unsure how to do so without error.

Thanks in advance for your advice/help

0

I just thought I'd answer myself in case anyone else comes across the same issue. I had to set Test.setFixedSearchResults() for the SOSL queries to work ok in test classes as per the following https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_SOSL.htm

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.