0

I'm creating a package with a simple Apex class that retrieves info about knowledge article (Lighting Knowledge). However, I'm having an issue with a test. When installing the package via installation link on another org, it fails with the following error:

The name "Knowledge__kav" is already used on component type: Article Type. Please rename existing component.

My understanding was that Knowledge__kav is a default record type for knowledge articles. In the other case, what is the correct way to implement the test?

public with sharing class ContentController {
    @AuraEnabled(cacheable=true)
    public static KnowledgeArticleVersion getArticleById(Id id) {
    return [
      SELECT Title, ArticleCreatedDate
      FROM KnowledgeArticleVersion
      WHERE Id = :id
      AND PublishStatus = 'Online'     
    ];
  }
}
@IsTest
private class ContentControllerTest {
  @IsTest static void validateGetArticleById() {
    String articleTitle = 'Test Article';
    String articleBody = 'Test Body';
    String articleUrlName = 'test';
    String language = 'en_US';

    Knowledge__kav article = new Knowledge__kav(
      Title = articleTitle,
      Summary = articleBody,
      UrlName = articleUrlName,
      Language = language
    );

    insert article;

    Knowledge__kav currentArticleDetail = [
      SELECT ArticleCreatedDate, ArticleNumber
      FROM Knowledge__kav
      WHERE Id = :article.Id
    ];

    KnowledgeArticle knowledgeArticle = [
      SELECT Id
      FROM KnowledgeArticle
      WHERE ArticleNumber = :currentArticleDetail.get('ArticleNumber').toString()
    ];

    KbManagement.PublishingService.publishArticle(knowledgeArticle.Id, true);

    sObject articleDetail = ContentController.getArticleById(article.Id);
    System.assertEquals(articleTitle, articleDetail.get('Title'));
  }
}
  • 1
    It sounds more like you are including Knowledge__kav in your package. – Daniel Hoechst Apr 24 at 15:24
  • @DanielHoechst just checked the content of the package. Knowledge__kav has added automatically because there are references in the test. And it can't be deleted. Is there a workaround for this? – Andrey Metelsky Apr 24 at 18:26
  • I am not a packaging expert. You might want to ask a new question specifically about how to make the package correctly. – Daniel Hoechst Apr 25 at 19:33

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.