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
Nivea NairNivea Nair 

How to identify article attached to a case using apex?

Hi,

Can anyone please tell me how to identify an article is attached to case using apex using Apex?
Please note that the case is not opened in the edit mode.

Thanks in advance!

Best Regards,
Nivea
Vasani ParthVasani Parth
Nivea,

Hope you have gone though this link:  http://help.salesforce.com/HTViewHelpDoc?id=console2_find_articles.htm&language=en_US

When you look at a case, you should be able to see a Solutions section (subject to page layout for the case - if you don't see it, you will need to add it to the page layout for the case).
The solutions section has a "View Suggested Solutions" button which tries to match the case contents up with an existing solution. It also has a search box to allow you to search for keywords in existing solutions, which is more commonly how we use it. This provides a list of solutions, and clicking Select at the left of the appropriate solution will associate it with the case.

Please mark this as the best answer if this helps
Sagar PareekSagar Pareek
Hi Nivea,

CaseArticle is the object you need to use
Here is the code snippet to give you an idea -
CaseArticle[] caseArticles = [SELECT KnowledgeArticleId FROM CaseArticle WHERE CaseId = :RecordId];

list<Id> kaIds = new List<Id>();
for (CaseArticle art: caseArticles) {
  kaIds.add(art.KnowledgeArticleId);
}

 KnowledgeArticleVersion[] Articles = [SELECT Id, KnowledgeArticleId, UrlName, Title, Summary, LastPublishedDate, ArticleType 
            FROM KnowledgeArticleVersion 
            WHERE PublishStatus= 'Online' 
            AND Language = 'en_US'
            AND KnowledgeArticleId IN :kaIds];

 
Nivea NairNivea Nair
Thank you both!

The problem I am actually encountering is that:
I have a checkbox 'Is KA attached' in Case object which should show whether an article is attached/not in the case. I have written a before Update trigger so that whenever an article is attached in the case, the checkbox is checked. The issue here is that whenever an article is attached to a case, the case is not getting updated because we do not have to edit a case in oder to attach an article. Hence, after I attach the Knowledge article in a case, only if I update the case, the checkbox gets checked. So now the question is : how can we make the checkbox checked whenever an article is attached to the case without updating the case.

Thanks & Regards,
Nivea
Sebastian PageSebastian Page
Hi Nivea ,

I have same requirment in our company please tell me are you got solution or not.

Regards
Sebastian