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
newbee developernewbee developer 

SOSL Query for Knowledge Object to retrieve Publish and Draft articles

Hi,

I am displaying results from SOSL query in a page block table.
For salesforce knowledge articles, "where" condition for "publish status" is mandatory to be mentioned.
Public List<Testing__kav> kbList{get;set;}
List<List<sObject>> search_results = [FIND :searchStr1 IN ALL FIELDS RETURNING Knowledge__kav
                                                             (Id,Title,Summary WHERE PublishStatus = 'Online') ];  
 kbList = search_results_dr[0];
 
But This only retrieves articles with online status. 
I also need articles with Draft Status, for which i have written another sosl query: 

List<List<sObject>> search_results_draft = [FIND :searchStr1 IN ALL FIELDS RETURNING Knowledge__kav
                                                             (Id,Title,Summary WHERE PublishStatus = 'Draft') ];  

How to combine these two sosl queries and add the result to my object kbList so that i can display in VF page in one single table? 
 
Best Answer chosen by newbee developer
Amit Yadav 9Amit Yadav 9
Hi newbee developer,

I don't think it will be possible to merge the queries.
But you can combine the results in same list and use that list to display records on vf page

Thanks
Amit.

All Answers

Amit Yadav 9Amit Yadav 9
Hi newbee developer,

I don't think it will be possible to merge the queries.
But you can combine the results in same list and use that list to display records on vf page

Thanks
Amit.
This was selected as the best answer
newbee developernewbee developer
Thanks for the response Amit. Could you please help me with combining the results in same list? 
I already have a list Public List<Testing__kav> kbList{get;set;}
In this list, I am adding Published Articles from the respective query.
How to add the results of second query to same list? Please guide me here!
 
newbee developernewbee developer
I am able to achieve this. Thanks Amit!! 
Steve NaborsSteve Nabors
Do you have the full code to do this?  We are needing this functionality for KB authors to more easily search all articles in the system, in order to make sure they don't create duplicate articles, etc.   We can use global search for published articles but there isn't an easy way to search Draft articles.  Would be nice to have a custom button to enter search criteria and then searched published and draft articles for a match.
Hyder Gani AHyder Gani A
1, Create  list for Draft  KB
2,Create  another list for published KB
3,Create Third list and use AddAll() method to merge first two list into 3rd list and return 3rd list.