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
Chuck RamseyChuck Ramsey 

Using ConnectApi

My Org is Spring '20 (API V48). According to the Apex documentation, the ConnectApi class has several methods to query Managed Content.  I'm trying to use getManagedContentByTopics with no success so far.

According to the Apex guide this should work:
ConnectApi.ManagedContentVersion Collection mcvc = ConnectApi.getManagedContentByTopics(networkId, 'My Topic', 0,1,'MyContentType);

I consistently get the error "Variable does not exist: ConnectApi" with a line number and column number corresponding to ConnectApi.getManagedContentByTopics.

What have I missed?
Best Answer chosen by Chuck Ramsey
Chuck RamseyChuck Ramsey
As too frequently happens, the Salesforce documentation of the API is incomplete and one must search high and low to find missing pieces of the puzzle.  I found my missingpiece in this blog post: Content Delivery API to Extend or Integrate Content (https://developer.salesforce.com/blogs/2019/11/content-delivery-api-to-extend-or-integrate-content.html)

The correct form is:
 
Id networkId = <insert code to fetch the Id of your Community>
List<String> contentTopics = new List<String>{'My Topic'};
Integer pageParam = 0;
Integer pageSize = 1; 
String myLanguage = 'en_US';
String myContentType = 'MyContentType';
ConnectApi.ManagedContentVersion Collection mcvc = ConnectApi.ManagedContent.getManagedContentByTopics(networkId, contentTopics,  pageParam, pageSize, myLanguage,myContentType);

 

All Answers

VinayVinay (Salesforce Developers) 
Hi Ramsey,

Can you please try using below.

ConnectApi.ManagedContentVersion Collection mcvc = new ConnectApi.getManagedContentByTopics(networkId, 'My Topic', 0,1,'MyContentType);

You might be missing 'New'.

Kindly let me know if it helps you and your query by marking it as Best Answer so that it can help others in the future.

Thanks,
Vinay Kumar
 
Chuck RamseyChuck Ramsey
I get this error: 
Invalid type: ConnectApi.getManagedContentByTopics
Chuck RamseyChuck Ramsey
As too frequently happens, the Salesforce documentation of the API is incomplete and one must search high and low to find missing pieces of the puzzle.  I found my missingpiece in this blog post: Content Delivery API to Extend or Integrate Content (https://developer.salesforce.com/blogs/2019/11/content-delivery-api-to-extend-or-integrate-content.html)

The correct form is:
 
Id networkId = <insert code to fetch the Id of your Community>
List<String> contentTopics = new List<String>{'My Topic'};
Integer pageParam = 0;
Integer pageSize = 1; 
String myLanguage = 'en_US';
String myContentType = 'MyContentType';
ConnectApi.ManagedContentVersion Collection mcvc = ConnectApi.ManagedContent.getManagedContentByTopics(networkId, contentTopics,  pageParam, pageSize, myLanguage,myContentType);

 
This was selected as the best answer