0

I have a requirement to update a field in a case when an article is attached to the case.

Any advice about which object should be trigger?

We are using the lightning knowledge base.

  • The trigger is on whatever object is assigned a lookup / parent Id to the Case – cropredy Sep 15 at 21:16
  • @cropredy caseArticle object cannot be triggered – Leo Sep 16 at 7:57
0

Welcome to SF.SE Leo. From your description, it sounds like you're perhaps attaching the knowledge article to the Case Record from the Knowledge Component. If not, you're likely doing it from someplace within a Knowledge Search where you still have the Case Record in context. By adding the knowledge article as an attachment to the Case record, it's clear you'll want to update the Case record (the parent) to reflect it now has a child attachment.

Without knowing the details of your method, it's difficult to give you precise directions on what "should" be what you're referring to as the "trigger". It's clear to me that it isn't the Knowledge Article.

That leaves either Attachment or the Case Object. I can tell you that Attachment is going to be a child of Case and you'll likely need to begin by creating a new Attachment from the Knowledge Article. At some point the attachment will need to be parented by referencing the CaseId.

  • i need to fire a trigger when i attach an article to a case from the knowledge component. i am using lightning, so the articles from the KnowledgeArticleVersion object are attached to the case from the CaseArticle object that cannot be triggered. – Leo Sep 16 at 7:16
  • It sounds like you're saying the trigger for the Attachment is not being called when when the update Case trigger code is executed. If that's the situation, you'll need to edit your post to add your code for the two triggers so we can review them to help diagnose the problem. Without it, we're just guessing. It may have to do with the order in which the DML is executed in either your Component or in your Case Trigger logic. – crmprogdev Sep 16 at 14:33
0

Background

  • CaseArticle is a junction object between Case and KnowledgeArticle and is inserted by SFDC when you attach a Knowledge Article to a Case in Service Console
  • There is no trigger support on CaseArticle so an after insert event can not be used to signal processing on the parent Case.

However,

When an article is attached, there is a FeedItem created that has these useful fields:

  • Type = AttachArticleEvent
  • ParentId (the Case's Id)

So, since you can write triggers on FeedItem, you can detect FeedItems on afterInsert where:

Set<Id> interestingCaseIds = new Set<Id>();
for (FeedItem fi: Trigger.new) {
  if (fi.Type = 'AttachArticleEvent' && 
      fi.ParentId != null &&
      fi.ParentId.getSobjectType() == Case.SobjectType) {
      interestingCaseIds.add(fi.ParentId);
  }
}

// do something useful for the Cases in interestingCaseIds  

You can also vote up this Idea for Triggers on CaseArticle

  • Thanks @cropredy.. actually i created a trigger for feeditem, and tried this approach but in this case the problem is that when we attach the article the trigger is not fired at all even if the record is created for feedItem obj. However, when we write a manual post the trigger fired. – Leo Sep 17 at 7:23
  • Another approach was to create a checkbox field in the case obj and with a process builder mark as checked when the feedItem record with type='AttachArticleEvent' is created. In this case i have the same problem and the checkbox is not checked, but if i change the process builder to mark the check box when the feeditem record is type='TextPost' it works fine. So it seems that is not working if the type of the feedItem record is 'AttachArticleEvent'. @cropredy – Leo Sep 17 at 11:10
  • @Leo - ugh; I didn't see this excluded in the doc but looking harder I found this confirmation for what you observed. At this point, I'd go with a scheduled job approach to sweep up FeedItems of this type and update the parent – cropredy Sep 17 at 17:13

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.