+ Start a Discussion
MikeyJamJamsMikeyJamJams 

How to query Salesforce CMS images?

Hello, 

I am exploring how to leverage Salesforce CMS for internal users. CMS was built around Experience Cloud, and displaying your content to external users, as the Experience Builder allows you to add CMS Lightning Components to your communities to pull in single pieces of content as well as collections. However, none of this is available for internal users. We would like to use CMS internally, so that content can be displayed on Lightning home pages for internal users. To do this we need to create custom components, but the process of querying and accessing CMS data seems very cumbersome. 

As far as I can tell, CMS is managed within the ManagedContent object. Unfortunately, this object is not available through SOQL. Instead, you have to use the ConnectAPI to access this information. There are a number of methods available to retrieve the CMS data, as listed here: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_ConnectAPI_ManagedContent_static_methods.htm#apex_ConnectAPI_ManagedContent_methods

However, all of these functions appear to be intended for external audience, as they want you to supply a channel id, or a community id of where the content is to be hosted. I'm looking to do something much more simpler, such as retrieve an image simply based on the name. 

I'm curious if others have tried to query for CMS content in a similar manner, and if you could provide an example, that would be wonderful! 

Thanks,
Mikey
AnudeepAnudeep (Salesforce Developers) 
Hi Mikey, 

CMS usage can be broadly categorized into Authoring and Delivery - the former being where images are uploaded and worked on and when ready will be made available for consumption in a Channel. So to address your question, it depends on the use case of in what stage of the image record you want to access it. You are right that ManagedContent is not SOQL enabled and currently, the authoring APIs are also not public yet as we are waiting to harden them before making it available broadly. When the images are published to a channel you can retrieve it as you saw through the Connect APIs as you indicated. Supplying a channel ID is not that cumbersome, you can publish the content to a headless channel ( means it will not be used in Communities) and use the Connect APIs to retrieve it from there.

Let me know if it helps. If it does, please mark this answer as Best. It may help others in the community. Thank You!

Anudeep