You need to sign in to do that
Don't have an account?
Hermann Ouré
Trigger Field update on knowledge when record is created on custom object
Hello,
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:
known error Article:
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 update 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
Apex Trigger
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:
known error Article:
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 update 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){ kavIds.add(jissue.Id); } } //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; lstKav.add(kav); } } } update lstKav; } } }
Apex Trigger
trigger JiraLinkKnownErrorArticle on JIRA_Issue__c (after insert, after update) { if(trigger.isAfter){ KnowledgeKavManager.updateJiraIssue(Trigger.New); } }
Apex Class:
Apex Trigger:
All Answers
Hi Hermann,
Try the below code, should work for you
Thanks for your reply.
I tried with your code but I am still unable to update the field Jira Issue on knowledge. So I am trying a workaround as to update a custom lookup field (First_JIRA_Issue_Number__c) on Case object first then update the knowledge field.
But even here, I am still unable to update the field First_JIRA_Issue_Number__c on Case with the related Jira Number
Basically from a Case, I have the possibility to create a Jira Issue (object: JIRA_Issue__c).
When the Jira Issue is created, the field First_JIRA_Issue_Number__c needs to be updated with the Jira Number. In this example the field First Jira Issue Number on Case is updated with JIRA000692
I have updated my class and the trigger but still does not work.
Apex Class:
Apex Trigger
Apex Class:
Apex Trigger: