---
schema_version: "1"
id: 08a6e3ad2bc2347ff597ae33db9d2a27a330ee0f5804bb1ee4e9211b68d8c869
title: Salesforce Knowledge with SOQL and SOSL
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/service-cloud/knowledge/guides/knowledge-development-soql-sosl-intro.md
canonical_url: https://developer.salesforce.com/docs/service/salesforce-knowledge-dev-guide/guide/knowledge-development-soql-sosl-intro.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: fd77cd4b12f487a73ca25bea7c5f2b789a9f88b74fd3fa6d94f25153a1b2b3a8
products:
  - Salesforce Knowledge Developer Guide
  - Service Cloud Developer Content
---

# Salesforce Knowledge with SOQL and SOSL

Use the Salesforce Object Query Language (SOQL) to search your organization's Knowledge data for specific information. SOQL is similar to the SELECT statement in the widely used Structured Query Language (SQL) but is designed specifically for Salesforce. Use the Salesforce Object Search Language (SOSL) to construct text-based search queries against the search index.

Keep the following limits in mind when querying `KnowledgeArticleVersion`.

- Filter on a single value of PublishStatus for best results. To find all versions of each article, omit the PublishStatus filter, but do filter on one or more master key IDs. To retrieve all archived versions for a given article, specify a SOQL filter where IsLatestVersion is `false`.
- In API version 46.0 and earlier, queries without a filter on PublishStatus return published articles by default. In API version 47.0 and later, draft, published, and archived articles are returned when Lightning Knowledge is enabled.
- To support security, only users with the "View Draft Articles" permission see articles whose PublishStatus value is `Draft`. Similarly, only users with the "View Archived Articles" permission see articles whose PublishStatus value is `Archived`.
- Archived article versions are stored in the `{Knowledge}__kav` object. To query archived article versions, specify the article Id and set `IsLatestVersion='0'`.

You can't use binding variables in Apex SOQL statements with KnowledgeArticleVersion objects. For example, the following SOQL statement causes a compilation error.

```soql
final String PUBLISH_STATUS_ONLINE = 'Online';
List<Knowledge__kav> articles = [
SELECT Id FROM Knowledge__kav
WHERE PublishStatus = :PUBLISH_STATUS_ONLINE
];
```

Instead, use dynamic SOQL as follows. See [Dynamic SOQL](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dynamic_soql.htm) in _Apex Developer Guide_.

```soql
final String PUBLISH_STATUS_ONLINE = 'Online';
final String q = 'SELECT Id, PublishStatus FROM Knowledge__kav
WHERE PublishStatus = :PUBLISH_STATUS_ONLINE';
List<Knowledge__kav> articles = Database.query(q);
```

For generic SOQL and SOSL information see the [SOQL and SOSL Reference](https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/).
