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
sushieatersushieater 

knowledge ID confusion

Hi, I'm new to apex and salesforce in general and am trying to implement a public knowledge site.

 

I've added a custom field, "buildTOC" to a "self_help" knowledge article type and have been trying to create a custom page to display this article type. The idea is that I have some articles that require a table of contents and I am going to generate this using javascript once the page is delivered based on the value of "buildTOC" for that article.

 

I'm customizing the knowledgeController w/ an extra function, "getBuildTOC". In it I'm trying to get the article id by using the following as seen in the examples.

 

 

Id id = ApexPages.currentPage().getParameters().get('id');

 

 

 

This gets me an ID that looks like kA0A0000000PTub.

 

I'm trying to query buildTOC based on that ID,

 

 

 List<Self_Help__kav> articles = [SELECT id, title ,BuildIndex__c FROM Self_Help__kav WHERE id = :id];

 But I always get an empty recordset.

 

 

Trying to figure out why, I tried executing the following query in the SystemLog executor.

 

 

system.debug([select title,id from self_help__kav where publishStatus='online' and language='en_US']);

 

 

Which returns me a list of records including the article that I am refering to earlier. The problem is that it lists it as a different ID. The result of this query lists it as ka0A0000000PUKvIAO and if I hardcode that value into my earlier query, I get a proper record returned.

 

How do I access this "other" id from page parameters or is there a different way to do this that I'm missing? Why is there two ID's? Is one the published ID?

 

Thanks!

 

francoisLfrancoisL

The fact that you have 2 objects on Knowledge, Knowledge Article and Knowledge Article Version. There is one Knowledge Article with multiple Version. The content is store in Knowledge Article Version but to access an article, you need to know the Knowledge Article Id. 

 

More info can be find here: 

http://www.salesforce.com/docs/developer/knowledge_devpre/index.htm

sushieatersushieater

Thanks very much. I knew it had to do with that, but the relationship wasn't straight. I was missing knowledgeArticleId as the foreign key in KnowledgeArticleVersion.

 

This diagram cleared up the relationships also.

http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_guidelines_knowledge.htm

 

Something like this will accomplish what I need.

 

 

system.debug([select id, BuildIndex__c from Self_Help__kav where ( knowledgeArticleId='kA0A0000000PTub') and PublishStatus='online']);

or

[select id, BuildIndex__c from Self_Help__kav where ( knowledgeArticleId=:id) and PublishStatus='online']

 

 

Rishi Kumar 53Rishi Kumar 53
Try this.

SELECT Id,KnowledgeArticleId,Language,Type__c ,PublishStatus,Summary,Link__c,Embedded_Video__c,
                                          SystemModstamp,Title,ArticleNumber, CreatedDate,
                                          OwnerId,VersionNumber,FirstPublishedDate,Attachment__Name__s, KnowledgeArticleId
                                     FROM User_Documents__kav 
                                    WHERE Id ='ka73B0000004C9IQAU'