Book Image

Visualforce Development Cookbook

By : Keir Bowden
Book Image

Visualforce Development Cookbook

By: Keir Bowden

Overview of this book

Visualforce, in conjunction with Apex, makes it easy to develop sophisticated, custom UIs for Force.com desktop and mobile apps without having to write thousands of lines of code and markup. The "Dynamic Binding" feature of Visualforce lets you develop generic Visualforce pages to display information related to the records without necessarily knowing which data fields to show. This is accomplished through a formula-like syntax, which makes it simple to manage even a complex hierarchy of records. "Visualforce Development Cookbook" provides solutions for 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 required help throughout. "Visualforce Development Cookbook" starts with explaining the simple utilities and builds up to advanced techniques for data visualization and reuse of functionality. This book contains recipes that cover various topics like 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. "Visualforce Development Cookbook" provides lots of practical examples to enhance and extend the Salesforce user interface.
Table of Contents (16 chapters)
Visualforce Development Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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 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 by clicking on Your Name | Setup | Develop | 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 | 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 by 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.

    Tip

    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, Step 1. New Custom Components, enter Case Count by Status in the Name field, select the HTML Area option, and click on the Next button.

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

  18. Select the Show HTML box.

  19. Paste the following markup into the editable area:

    <iframe style="border: none" src="/apex/CasesSidebar"  seamless=""></iframe>
  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, 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, 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.

    Tip

    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 nonclosed 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 were to leave 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.