For a particular case, I have the possibility to create a Jira issue (in custom object: JIRA_Issue__c) and an Article for Known Errors (in object Knowledge__kav)

Jira Issue:

enter image description here

known error Article:

enter image description here

In this example I have create a Jira Issue (JIRA000659) and an Article for the case 00161455.

What I am struggling with is that the lookup field Jira Issue on the article (Knowledge__kav object) needs to be updated with the Jira Number (JIRA000659). Only a Jira Issue can be created before an article is created. Alternatively a Jira Issue can also be created after an article has been created. In both case the field Jira Issue on Knowledge has to be updated with the Jira Issue Number JIRA000659 associated to the case (00161455)

I have written a class and created a trigger on the custom object JIRA_Issue__c. But nothing happens, I can't get the right logic.

Could someone help? Thanks

Apex class

public class KnowledgeKavManager {

public static void updateJiraIssue(List<JIRA_Issue__c> lstJira) {
    Set<Id> kavIds = new Set<Id>();
    //Id KnownErrorRecordTypeId = schema.SObjectType.Knowledge__kav.getRecordTypeInfosByName().get('Known_Error').getRecordTypeId();
    for(JIRA_Issue__c jissue : lstJira){
        if(jissue.Case__c != null){
    //Get Articles where related problem Id = Jira case__c Id
    //Map<Id,Knowledge__kav> KavMap = new Map<Id,Knowledge__kav>([SELECT Id FROM Knowledge__kav WHERE Related_Problem__c IN: kavIds AND RecordTypeId =:KnownErrorRecordTypeId]);
    Map<Id,Knowledge__kav> KavMap = new Map<Id,Knowledge__kav>([SELECT Id FROM Knowledge__kav WHERE Related_Problem__c IN: kavIds]);
    List<Knowledge__kav> lstKav = new List<Knowledge__kav>();
    for(Knowledge__kav kav: KavMap.values()){
        System.debug('##### KavMap.values ' + KavMap.values() );
        if(KavMap != null && KavMap.containskey(kav.Related_Problem__c)) {
            List<JIRA_Issue__c> lstJiraIssue = new List<JIRA_Issue__c>();
            for(JIRA_Issue__c ji: lstJiraIssue){
                if(ji.Case__c == kav.Related_Problem__c){
                    kav.JIRA_Issue__c = ji.Id;
        update lstKav;           


Apex Trigger:

trigger JiraLinkKnownErrorArticle on JIRA_Issue__c (after insert, after update) {


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.