function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

What would be the easiest way to create an KB article from a trigger?


We are currently in the process of implementing a approval process for KB articles. Everything is stored in a temporary SObject (CSO_CRM__c), so it can go through the approval process and have all needed modifications before becoming an article.

I have created a trigger that runs after update and if the temporary article has been approved by all approvers (Closed status), I want to create the KB article.

I still need to implement all of my datacategoryselections but, in this code snip im getting this following error:


There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Apex trigger CSO_CRM_After caused an unexpected exception, contact your administrator: CSO_CRM_After: execution of AfterUpdate caused by: System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Knowledge Article Version]: [Knowledge Article Version]: Trigger.CSO_CRM_After: line 51, column 1". 


How do I create the Knowledge Article Version?


or is there a better way to do all this?


trigger CSO_CRM_After on CSO_CRM__c (after update) {
List<CSO_CRM__c> crmTranslation = new List<CSO_CRM__c>();
List<FAQ__Kav> articleList = new List<FAQ__Kav>();
List<FAQ__DataCategorySelection> dataCategoryList = new List<FAQ__DataCategorySelection>();
for(CSO_CRM__c crm :{
if(crm.Status__c == 'Closed'){
//Insert Article
FAQ__Kav article = new FAQ__Kav();
article.answer__c = crm.answer__c;
article.Chat_Answer__c = crm.Chat_URL__c;
article.keywords__c = crm.Keywords__c;
article.model_number_update__c = crm.model_update__c == true ? 'Yes' : 'No';
article.summary = crm.summary__c;
article.title = crm.title__c;
article.UrlName = crm.title__c;

//Insert all Internal Documents
String tempIntDoc = crm.Internal_Classification__c;
tempIntDoc = tempIntDoc.removeStart('[');
tempIntDoc = tempIntDoc.removeEnd(']');
List<String> docs = tempIntDoc.split(',');
for(String doc : docs){
FAQ__DataCategorySelection dCat = new FAQ__DataCategorySelection();
dCat.ParentId =;
dCat.DataCategoryGroupName = 'Internal_Documents';
dCat.DataCategoryName = doc;
if(crm.type__c != 'Translation'){
String tempLanguages = crm.Languages__c;
tempLanguages = tempLanguages.removeStart('[');
tempLanguages = tempLanguages.removeEnd(']');
List<String> languages = tempLanguages.split(',');
for(String lang : languages){
CSO_CRM__c tran = crm.clone(false,false,false,false);
tran.Type__c = 'Translation';
tran.Language__c = lang;
tran.Status__c = 'New';
tran.Master_ID__c = crm.Id;

insert crmTranslation;
insert articleList;
insert dataCategoryList;