+ Start a Discussion
ArchieTechie6ArchieTechie6 

Salesforce Knowledge - Fetch Articles which are Submitted to Approval

Hello All, 

I want to fetch KB Articles which are "Submitted for Approval".

In PublishStatus - We only have two values - Draft and Published.

How to query articles which are in Draft and Submitted to Approval(These are displayed with lock Symbol).
 
SELECT PublishStatus FROM KnowledgeBase__kav

The above query doesnt return the status which explains that article is submitted for approvals.

Could anyone help me here?
NagendraNagendra (Salesforce Developers) 
Hi,

By default, only online articles will be queried alongside your default language in knowledge settings.

That being said, your current SOQL will only display online.

First, you will need to query for the Ids of the draft articles. (I encourage you to check the documentation for the sObjects to know what fields you can query on at Salesforce Knowledge Developer Guide https://developer.salesforce.com/docs/atlas.en-us.knowledge_dev.meta/knowledge_dev/sforce_api_objects_knowledgearticleversion.htm )

Then, to be able to query for articles that are currently going through an approval process you will need to fetch a list of ID' currently in draft and then query ProcessInstance IN list of ID's of your draft articles

you will then have a list of draft articles going through an approval process (if any)

you can check this https://salesforce.stackexchange.com/questions/30977/check-if-a-record-is-in-approval-process post for checking for records going through an approval process.

example query:
SELECT Id, TargetObjectIdFROM ProcessInstance WHERE TargetObjectId IN :recordIds
Hope this helps.

Kindly mark this as solved if it's resolved.

Thanks,
Nagendra