Sync Salesforce Knowledge Articles to External Systems

Sync Salesforce Knowledge Articles to External Systems

A Simple Guide: One-Way Sync Salesforce Lightning Knowledge to a Third-Party App

Salesforce Lightning Knowledge is a powerful tool for managing your organization’s information, but its value multiplies when you can share that knowledge with other systems. Whether you’re feeding a public-facing website, an internal portal, or another support application, keeping that data in sync is critical.

Instead of building a complex, event-driven integration, you can implement a highly effective and lightweight one-way sync using a polling mechanism with Salesforce’s REST API.

This guide will walk you through a simple, two-step process: an initial full load followed by ongoing delta syncs to capture changes.


🚀 Step 1: The Initial Load – Getting All Published Articles

First, you need to pull a complete baseline of all your current, published Knowledge articles. This is a one-time operation to populate your third-party application.

We will use the standard Salesforce Query REST API for this. The key is to fetch only the articles that are currently live and are the latest versions.

SOQL Query

Use the following SOQL query to select the necessary fields from the Knowledge Article Version object (Knowledge__kav).

SELECT Id, Title, ArticleNumber, Summary, Language
FROM Knowledge__kav
WHERE PublishStatus = 'Online'
  • PublishStatus = 'Online': Ensures you only get articles that are actively published.

API Endpoint

Execute this query using the query REST API endpoint:

/services/data/vXX.X/query?q=query

After this initial load, your third-party application will have a complete copy of all published Salesforce Knowledge articles.


🔄 Step 2: The Delta Sync – Capturing Ongoing Changes

Once the initial load is complete, you only need to query for what’s changed since your last sync. This is far more efficient than re-syncing everything.

For this, we’ll poll Salesforce periodically (e.g., every 15 minutes or every hour) using a timestamp of our last successful run (PreviousRunDateTime).

Critically, we must use the QueryAll REST API. This is because the standard query endpoint cannot see deleted records, but queryAll can, which is essential for handling deletions.

SOQL Query

Use this query to find articles that have been modified, published, or archived since the last run.

SELECT Id, Title, ArticleNumber, Summary, Language
FROM Knowledge__kav
WHERE PublishStatus IN ( 'Online', 'Archived' )
AND SystemModStamp >= PreviousRunDateTime
  • PublishStatus IN ( 'Online', 'Archived' ): This captures both new/updated articles (‘Online’) and unpublished articles (‘Archived’).
  • SystemModStamp >= PreviousRunDateTime: This is the magic. It only fetches records that have changed since your integration last ran.

API Endpoint

Execute this query using the queryAll REST API endpoint:

/services/data/vXX.X/queryAll?q=query

Sync Logic

When you process the results from this delta query, apply the following logic in your third-party application:

  • If PublishStatus is ‘Online’: The article is new or has been updated with newer version. Create the record in your target system using the Id as the unique identifier.
  • If PublishStatus is ‘Archived’: The article has been unpublished from Salesforce. Delete the corresponding record from your target system.

This “insert-and-delete” logic is simple and powerful, as it avoids the need for complex checks against your existing data.


📋 Key Implementation Considerations

As you build this integration, keep these critical points in mind.

1. Handling Pagination

Your SOQL queries (especially the initial load) may return thousands of records, exceeding the single API call limit (e.g., 2,000 records). Salesforce handles this gracefully.

  • Check the JSON response for a field named nextRecordsUrl.
  • If nextRecordsUrl is present and not null, it means there are more records to fetch.
  • Call the URL provided in nextRecordsUrl to get the next batch of results.
  • Repeat this process until nextRecordsUrl is null, indicating you have retrieved all pages.

2. Using the Unique Identifier

Always use the Salesforce Id (the 18-digit Knowledge Article Version ID) as the unique external key in your third-party application’s database. This makes the create, and delete operations simple and reliable.

3. A Caveat on Deletions

This polling method has one important limitation. It relies on finding a record with the PublishStatus = 'Archived'.

If a user archives an article and then permanently deletes it (i.e., clears it from the Salesforce Recycle Bin) before your next sync job runs, your queryAll call will not find that record. Your integration will miss the delete, and the article will remain in your third-party system as an orphan.

Leave a Reply