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.
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.
Sign up to join this communityI 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.
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.
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 ConsoleCaseArticle
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:
AttachArticleEvent
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