2

I need to query CreatedById field on Article. I tried using query from below, where 'articleId' represents 'recordId' from article page in community.

SELECT CreatedById,Id FROM KnowledgeArticle where Id = :'articleId'

It seems to me, that i am doing something wrong, i cannot get CreatedById from above query. The last thing i came up with is, to access articles i will need to access certain category first, so i will need to query different Objects (depending on category, Object_Name__ka) Is there any workaround?

6
  • Why can't you get CreatedById? Do you get an error? If so please include the message here verbatim. – Adrian Larson Apr 21 '17 at 14:09
  • Sorry, no records returned. Seems to me that i'm querying wrong object.. – Nikola Naumovski Apr 21 '17 at 14:11
  • Did you try querying Object_Name__ka? Are you sure there are actually records? – Adrian Larson Apr 21 '17 at 14:16
  • Yeah, there are records, its coming to my mind now that maybe 'recordId' does not represent the 'Id' in Object_Name__ka table. – Nikola Naumovski Apr 21 '17 at 14:23
  • You're supposed to substitute the actual value. No record would ever have an actual id of 'articleId'. – Adrian Larson Apr 21 '17 at 14:24
1

Just in regards to the Id values themselves, you can determine the specific type you need to query by using a script like the following:

Id dummyId = Id.valueOf('ka0'.rightPad(15, '0'));
system.debug(dummyId.getSObjectType());

So if that yields Some_Article_Type__ka, you would query:

SELECT CreatedById FROM Some_Article_Type__ka WHERE Id = 'ka0...'

You can run that script in Execute Anonymous, which you can get to via the Developer Console. The same process would apply for ka1, ka2, etc.

3

Article belongs to specific Article Type object.

To retrieve the CreatedById, you need to retrieve from Knowledge Article version object which end with _kav

SELECT Id,Title,UrlName,Summary,KnowledgeArticleId, CreatedById 
FROM Custom_Artile_Type__kav 
WHERE PublishStatus ='Online' AND Language ='en_US'
AND KnowledgeArticleId = 'kA2160000005CpjCAE'

Moreover, there are also restriction firing the SOQL query:

Implementation restriction:

When querying the Custom_Artile_Type__kav object, you must filter using the following syntax:

  1. Id = [single ID], Id IN [list of ID's] or Language = [language ISO code] or PublishStatus = [status]

  2. In addition Language is only permitted in a top-level AND condition.

To retrieve Data Categories, you need to query from __DataCategorySelection

SELECT Id, DataCategoryGroupName, DataCategoryName, ParentId
FROM Custom_Article_Type__DataCategorySelection

Again restriction

By the way, we cannot filter on DataCategoryGroupName, DataCategoryName in the above SOQL query.

So, filter and matching should have to be done in apex coding.

For more information, refer Articles

Knowledge relationship

2
  • 1
    Note that __kav is KnowledgeArticleVersion, whereas __ka is KnowledgeArticle. – Adrian Larson Apr 21 '17 at 14:23
  • correct you are, updating ans – Santanu Boral Apr 21 '17 at 14:25

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.