top of page

How to Eliminate the Bulky Manual Work For Salesforce Knowledge

Getting useful Salesforce knowledge to service agents is an important part of a successful Service Cloud implementation. Unfortunately, moving knowledge into Salesforce has often meant bulky manual work. In this article, we will learn to reduce the developer efforts and automate the following scenarios/problems for Salesforce knowledge articles:

  1. Submitting translations for all published articles in a particular language.

  2. Updating a field value of all published articles.

Batch utility to submit translations for all published support articles

The first scenario is a very common occurrence. For example, we have 20,000 support articles in our org to submit for translation to Spanish_Mexico. It is inconvenient to submit the translation manually for Spanish one by one. In order to reduce the developer’s manual efforts, you can use the below batch utility class to submit the translations for all of your support articles:

global with sharing class SubmitTranslationInSpanishBatch implements Database.Batchable <sObject>{
    global Database.QueryLocator start(Database.BatchableContext BC) {
     return Database.getQueryLocator([Select id, KnowledgeArticleId from FAQ__kav where PublishStatus='Online' AND language ='en_US']);
global void execute(Database.BatchableContext BC, List<sObject> supportArticles){
     for(FAQ__kav article : (List<FAQ__kav>)supportArticles){
     String articleId = article.KnowledgeArticleId ;
     String language = 'es_MX'; //es_mx is for spanish(mexico)
// assigned id can be the user or queue to  which this translations will be assigned for approval. 
     String assigneeId = '00G31000004VYZG'; //I am using hard-code one
// this is due date of translation approval
     Datetime dueDate = Datetime.newInstanceGmt(2015, 09,21); 
   // submitForTranslation() function is used to submit the translation.
String id =KbManagement.PublishingService.submitForTranslation(articleId, language, assigneeId, dueDate);   
global void finish(Database.BatchableContext BC) {
You can use this batch in multiple ways. For example, you can create a custom button, then redirect to a Visualforce page and pass the language for which you want to submit the translations. You can then call this batch from the Visualforce controller to submit the translations for more than one language.
Batch utility to update a custom field for all published support articles
There are several occasions when we may need to add a custom field on an article object, and so then we populate this field for all existing published articles. As we know, it is not simple to update an already published article, since they cannot be edited. In the below batch class, we will populate a custom field (Web_Product_date__c) for all already published support articles.
This batch class performs 3 actions to address the problem:
1. It opens published articles in editing mode, which is equivalent to draft status.
2, It then performs the updates on the articles that are now in draft status.
3. Finally, it re-publishes all of the articles that are in draft status from step 2.
global with sharing class PopulateFieldOnPublishedArticlesBatch implements Database.Batchable <sObject>{
    global Database.QueryLocator start(Database.BatchableContext BC) {
     return Database.getQueryLocator([SELECT Id, ArticleNumber, KnowledgeArticleId FROM FAQ__kav WHERE PublishStatus = 'online' and language = 'en_US']);
global void execute(Database.BatchableContext BC, List<sObject> supportArticles){
     List<Id> articleIDs = new List<Id>();
     List<String> articleNumbers = new List<String>();
     //Step 1: Open published articles in editing mode which is Draft status
     for(FAQ__kav a: (List<FAQ__kav>)supportArticles){
     String Id = KbManagement.PublishingService.editOnlineArticle(a.KnowledgeArticleId, true);
         if (Id == null) {
         System.debug('##### ERROR While Editing');
     List<FAQ__kav> articles = new List<FAQ__kav>();
     for (FAQ__kav d : [SELECT Id, KnowledgeArticleId FROM FAQ__kav WHERE PublishStatus = 'draft' AND Language = 'en_US' AND ArticleNumber IN :articleNumbers]) {
         // Step 2: perform your updates
         d.Web_Product_date__c = System.Now();
     if(articles.size() > 0){
     update articles;
     //Step 3: re-publish all the draft article of this batch.
     for (String articleId : articleIDs) {
         KbManagement.PublishingService.publishArticle(articleId, true);
global void finish(Database.BatchableContext BC) {

I hope both of the article batch utilities help you automate the manual work on articles of your Salesforce org. We will keep you updated with more utility scripts in the future.

9 views0 comments

Recent Posts

See All

Integrating Microsoft Yammer and Salesforce

In today's business environments, both customers and employees are social. Bringing social media into the workplace increases collaboration and connection with peers — anytime, anywhere. Salesforce an


bottom of page