Building Content-Rich Visualforce Pages with Salesforce CRM Content | Techila
single,single-post,postid-1254,single-format-standard,ajax_updown_fade,page_not_loaded,,qode_grid_1300,footer_responsive_adv,hide_top_bar_on_mobile_header,qode-content-sidebar-responsive,qode-theme-ver-9.4.2,bridge,wpb-js-composer js-comp-ver-4.12,vc_responsive

Building Content-Rich Visualforce Pages with Salesforce CRM Content


Building Content-Rich Visualforce Pages with Salesforce CRM Content


With Salesforce CRM Content, you can organize, share, search, and manage content within your organization and across key areas of the Salesforce application. This content can include all file types–from traditional business documents, such as Microsoft® PowerPoint® presentations–to Google Docs™ Web pages and audio, video, and image files.

In this blog post, you can learn about the benefits of storing and managing images in Salesforce CRM Content, and about how to use the power of Salesforce CRM Content and Visualforce to build dynamic pages.

Why Manage Images in Salesforce CRM Content?

The overall idea and functional requirements would be to build a Visualforce page that includes images that change relatively often (e.g., a page that shares global news stories). Because the images will change regularly, storing them as static resources in Visualforce pages and referencing them by URL in your Visualforce markup might not be such a great idea, as it might mean that the content management for the images and the page maintenance itself will require quite a bit of effort and changing code.

To simplify and streamline these tasks, you can use Salesforce CRM Content to manage the images. The versioning feature in Salesforce CRM Content makes it easy to upload new versions of a document, or in this case, a new image that represents the latest version of a document. All that you need to do in your page is reference the latest version of the document. After doing that, swapping out images is as easy as uploading a new document version.


How can you reference the images that you’ve stored in Salesforce CRM Content in your Visualforce markup? That’s where the Salesforce CRM Content thumbnail rendition servlet comes into play. The thumbnail rendition servlet is used for various common processes in Salesforce (e.g., rendering thumbnails and previews of files that are shared in Chatter posts), but it also has great, lesser-known applications, including the one that appears in this blog post.

Note: This application approach requires that Salesforce CRM Content licenses be assigned to all Salesforce users who access the Visualforce page.

Implementing your Visualforce Page and Apex Controller

Implementing the Salesforce CRM Content thumbnail rendition servlet is pretty straightforward.

Page Controller

In the Visualforce page controller, select the ID of the latest version of your document, using its document name or its contentDocId, which appears here.


public class MyPageController{

ContentVersion[]cvs = [select id from contentversion where contentdocumentid=<contentDocId> and isLatest=true];



Now that you have selected the ID of your latest document version, you can now build the Salesforce CRM Content thumbnail rendition servlet URL and assign it to a public controller variable.

public class MyPageController {

  public String imageUrl {get; set;}

ContentVersion[]cvs = [select id from contentversion where contentdocumentid=<contentDocId>and isLatest=true];

 imageUrl = '/sfc/servlet.shepherd/version/renditionDownload?rendition=THUMB720BY480&versionId=' + cvs[0].id;



Visualforce Page

In the Visualforce page markup, you can now use the <apex:image> component to reference the Salesforce CRM Content image. To do this, just add the controller variable that holds the thumbnail rendition servlet URL as the value for the url parameter.


<apex:page controller=”MyPageController”>

<apex:image url=”{!imageUrl}”... />



And you’re done! That’s really all there is to it. Swapping out images on this Visualforce page is going to be as easy as uploading a new document version to Salesforce CRM Content. No code changes in the Visualforce markup or the controller code are required!

Additional Salesforce CRM Content Considerations

When you consider using the Salesforce CRM Content approach for your Visualforce pages, it’s important to remember a few things.

·The Salesforce CRM Content thumbnail rendition servlet supports three different rendition sizes.

·         120 pixels × 90 pixels

·         240 pixels × 180 pixels

·         720 pixels × 480 pixels

The desired rendition size can be passed as a parameter in the URL:
/sfc/servlet.shepherd/version/renditionDownload?rendition=THUMB720BY480&versionId=’ + cvs[0].id;
For the three supported rendition sizes, the valid values for the rendition parameter are THUMB120BY90, THUMB240BY180, and THUMB720BY480.

·The thumbnail rendition servlet URL is not versioned. Also, while Salesforce doesn’t have any immediate plans to change it, the thumbnail rendition servlet URL is subject to change without notice.

When building high-volume public pages using Sites, it’s best to upload images as static resources and reference them as static resources on the page to take advantage of site caching and the Salesforce Content Delivery Network (CDN).  



Author: techila

No Comments

Post A Comment