Book Image

Visualforce Development Cookbook - Second Edition

By : Keir Bowden
Book Image

Visualforce Development Cookbook - Second Edition

By: Keir Bowden

Overview of this book

Visualforce is a framework that allows developers to build sophisticated, custom user interfaces that can be hosted natively on the Force.com platform. The Visualforce framework includes a tag-based markup language, similar to HTML that is used to write the Visualforce pages and a set of controllers that are used to write business logic to the Visualforce pages. Visualforce Development Cookbook provides solutions to a variety of challenges faced by Salesforce developers and demonstrates how easy it is to build rich, interactive pages using Visualforce. Whether you are looking to make a minor addition to the standard page functionality or override it completely, this book will provide you with the help you require throughout. You will start by learning about the simple utilities and will build up to more advanced techniques for data visualization and to reuse functionality. You will learn how to perform various tasks such as creating multiple records from a single page, visualizing data as charts, using JavaScript to enhance client-side functionality, building a public website, and making data available to a mobile device. With an interesting chapter on tackling common issues faced while developing Visualforce pages, the book provides lots of practical examples to enhance and extend your Salesforce user interface.
Table of Contents (16 chapters)
Visualforce Development Cookbook - Second Edition
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface

Visualforce in the sidebar


Visualforce is commonly used to produce custom pages that override or supplement standard platform functionality. Visualforce pages can also be incorporated into any HTML markup through the use of an iframe.

Note

An iframe, or inline frame, nests an HTML document inside another HTML document. For more information, visit http://reference.sitepoint.com/html/iframe.

In this recipe, we will add a Visualforce page to a Salesforce sidebar component. This page will display the number of currently open cases in the organization, and will be styled and sized to fit seamlessly into the sidebar.

Getting ready

This recipe makes use of a custom controller, so this will need to be created before the Visualforce page.

How to do it...

  1. Navigate to the Apex Classes setup page by clicking on Your Name | Setup | Develop | Apex Classes.

  2. Click on the New button.

  3. Paste the contents of the CasesSidebarController.cls Apex class from the code download into the Apex Class area.

  4. Next, create the Visualforce page by navigating to the Visualforce setup page, clicking on Your Name | Setup | Develop | Visualforce Pages.

  5. Click on the New button.

  6. Enter CasesSidebar in the Label field.

  7. Accept the default CasesSidebar that is automatically generated for the Name field.

  8. Paste the contents of the CasesSidebar.page file from the code download into the Visualforce Markup area.

  9. Click on the Save button to save the page.

  10. Navigate to the Visualforce setup page by clicking on Your Name | Setup | Develop | Visualforce Pages.

  11. Locate the entry for the CasesSidebar page and click on the Security link.

  12. On the resulting page, select which profiles should have access and click on the Save button.

    Note

    Ensure that all profiles whose sidebar will display the Visualforce page are given access. Any user with a profile that does not have access will see an Insufficient Privileges error in their sidebar.

  13. Next, create the home page component by navigating to the Home Page Components setup page, clicking on Your Name | Setup | Customize | Home | Home Page Components.

  14. Scroll down to the Custom Components section and click on the New button.

  15. If the Understanding Custom Components information screen appears, as shown in the following screenshot, click on the Next button:

    Note

    To stop this information screen appearing each time you create a home page component, select the Don't show this page again box before clicking on the Next button.

  16. On the next page, titled Step 1. New Custom Components, enter Case Count by Status in the Name field, select the Visualforce Area option, and click on the Next button.

  17. On the next page, titled Step 2. New Custom Components, select the Narrow (Left) Column option.

  18. Select CasesSidebar from the Visualforce Page select list.

  19. Enter 200 in the Height (in pixels) field.

  20. Click on the Save button.

  21. Next, add the new component to one or more home page layouts. Navigate to Your Name | Setup | Customize | Home | Home Page Layouts.

  22. Locate the name of the home page layout you wish to add the component to and click on the Edit link.

  23. On the resulting page, titled Step 1. Select the Components to show, select the Case Count by Status box in the Select Narrow Components to Show section and click on the Next button.

  24. On the next page, titled Step 2. Order the Components, use the arrow buttons to move the Case Count by Status component to the desired position in the Narrow (Left) Column list and click on the Save button.

  25. Repeat steps 22 to 24 for any other home page layouts that will contain the sidebar component.

    Note

    This will add the component to the sidebar of the home page only. To add it to the sidebar of all pages, a change must be made to the user interface settings.

  26. Navigate to Your Name | Setup | Customize | User Interface and locate the Sidebar section.

  27. Select the Show Custom Sidebar Components on All Pages box, as shown in the following screenshot, and click on the Save button:

How it works...

The component appears in the sidebar on all pages, showing the number of cases open for each non-closed status, as shown in the following screenshot:

There's more...

The case counts displayed in the sidebar will be retrieved when the page is displayed, but will remain static from that point. An action poller can be used to automatically refresh the counts at regular intervals. However, this will introduce a security risk, as each time the poller retrieves the updated information it will refresh the user's session. This means that, if a user leaves their workstation unattended, the Salesforce session will never expire. If this mechanism is used, it is important to remind users of the importance of locking their workstation should they leave it unattended.