Visualforce Development Cookbook - Second Edition
By Keir Bowden
()
About this ebook
- This book provides an enhanced user experience with dynamically-generated, reactive pages
- Access data over additional channels via public web sites and mobile pages
- Packed with easy-to-follow recipes, including step-by-step instructions and Apex/Visualforce code downloads this title is the all in one package you need to get more from Visualforce.
This book will be beneficial to developers who are already well-versed with the basics of Visualforce. An awareness of the standard component library and the purpose of controllers is expected.
Related to Visualforce Development Cookbook - Second Edition
Related ebooks
Visualforce Development Cookbook Rating: 0 out of 5 stars0 ratingsSilverlight 4 User Interface Cookbook Rating: 4 out of 5 stars4/5SAP BusinessObjects Reporting Cookbook Rating: 5 out of 5 stars5/5Windows Application Development Cookbook Rating: 0 out of 5 stars0 ratingsJIRA Development Cookbook - Third Edition Rating: 0 out of 5 stars0 ratingsVaadin 7 Cookbook Rating: 0 out of 5 stars0 ratingsDart Cookbook Rating: 0 out of 5 stars0 ratingsMicrosoft Dynamics CRM 2011 Scripting Cookbook Rating: 0 out of 5 stars0 ratingsJIRA 5.x Development Cookbook Rating: 0 out of 5 stars0 ratingsBuilding E-commerce Sites with VirtueMart Cookbook Rating: 5 out of 5 stars5/5ASP.NET MVC 2 Cookbook Rating: 0 out of 5 stars0 ratingsJIRA Development Cookbook Rating: 0 out of 5 stars0 ratingsWeb Development with Django Cookbook - Second Edition Rating: 0 out of 5 stars0 ratingswxPython Application Development Cookbook Rating: 0 out of 5 stars0 ratingsOracle APEX Cookbook - Second Edition Rating: 0 out of 5 stars0 ratingsMicrosoft Dynamics NAV 7 Programming Cookbook Rating: 0 out of 5 stars0 ratingsDotNetNuke 5.4 Cookbook Rating: 5 out of 5 stars5/5Xamarin Mobile Development for Android Cookbook Rating: 0 out of 5 stars0 ratingsYii Application Development Cookbook - Second Edition Rating: 0 out of 5 stars0 ratingsYii 1.1 Application Development Cookbook Rating: 0 out of 5 stars0 ratingsYii2 Application Development Cookbook - Third Edition Rating: 0 out of 5 stars0 ratingsOpenLayers Cookbook Rating: 0 out of 5 stars0 ratingsMicrosoft Dynamics NAV 2009 Programming Cookbook Rating: 0 out of 5 stars0 ratingsData Visualization with D3 4.x Cookbook - Second Edition Rating: 0 out of 5 stars0 ratingsOracle ADF Faces Cookbook Rating: 0 out of 5 stars0 ratingsSQL Server 2016 Reporting Services Cookbook Rating: 5 out of 5 stars5/5Meteor Cookbook Rating: 5 out of 5 stars5/5Flask Framework Cookbook Rating: 5 out of 5 stars5/5CakePHP 1.3 Application Development Cookbook Rating: 0 out of 5 stars0 ratingsSelenium Testing Tools Cookbook Rating: 3 out of 5 stars3/5
System Administration For You
Improve your skills with Google Sheets: Professional training Rating: 0 out of 5 stars0 ratingsLinux: Learn in 24 Hours Rating: 5 out of 5 stars5/5Linux Bible Rating: 0 out of 5 stars0 ratingsPractical Data Analysis Rating: 4 out of 5 stars4/5Learn Windows PowerShell in a Month of Lunches Rating: 0 out of 5 stars0 ratingsCybersecurity: The Beginner's Guide: A comprehensive guide to getting started in cybersecurity Rating: 5 out of 5 stars5/5Learn PowerShell in a Month of Lunches, Fourth Edition: Covers Windows, Linux, and macOS Rating: 0 out of 5 stars0 ratingsCompTIA A+ Complete Review Guide: Core 1 Exam 220-1101 and Core 2 Exam 220-1102 Rating: 5 out of 5 stars5/5Mastering Windows PowerShell Scripting Rating: 4 out of 5 stars4/5Learn PowerShell Scripting in a Month of Lunches Rating: 0 out of 5 stars0 ratingsEthical Hacking Rating: 4 out of 5 stars4/5Operating Systems DeMYSTiFieD Rating: 0 out of 5 stars0 ratingsMastering Active Directory Rating: 0 out of 5 stars0 ratingsLinux Command-Line Tips & Tricks Rating: 0 out of 5 stars0 ratingsLinux for Beginners: Linux Command Line, Linux Programming and Linux Operating System Rating: 4 out of 5 stars4/5Learn SQL Server Administration in a Month of Lunches Rating: 3 out of 5 stars3/5ConfigMgr - An Administrator's Guide to Deploying Applications using PowerShell Rating: 5 out of 5 stars5/5PowerShell: A Comprehensive Guide to Windows PowerShell Rating: 4 out of 5 stars4/5Building a Plex Server with Raspberry Pi Rating: 0 out of 5 stars0 ratingsBash Command Line Pro Tips Rating: 5 out of 5 stars5/5Summary of Lights Out: by Ted Koppel | Includes Analysis Rating: 0 out of 5 stars0 ratingsLearning Linux Shell Scripting Rating: 4 out of 5 stars4/5Networking for System Administrators: IT Mastery, #5 Rating: 5 out of 5 stars5/5Mastering Linux Shell Scripting Rating: 4 out of 5 stars4/5Learn Git in a Month of Lunches Rating: 0 out of 5 stars0 ratings
Reviews for Visualforce Development Cookbook - Second Edition
0 ratings0 reviews
Book preview
Visualforce Development Cookbook - Second Edition - Keir Bowden
Table of Contents
Visualforce Development Cookbook - Second Edition
Credits
About the Author
About the Reviewer
www.PacktPub.com
eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Sections
Getting ready
How to do it…
How it works…
There's more…
See also
Conventions
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
Questions
1. General Utilities
Introduction
Overriding standard buttons
Getting ready
How to do it...
How it works...
Data-driven styling
How to do it...
How it works...
See also
Turning off an action poller
Getting ready
How to do it...
How it works...
See also
Visualforce in the sidebar
Getting ready
How to do it...
How it works...
There's more...
Passing parameters to action methods
Getting ready
How to do it...
How it works...
Reacting to URL parameters
Getting ready
How to do it...
How it works...
See also
Passing parameters between Visualforce pages
How to do it...
How it works...
See also
Opening a pop-up window
How to do it...
How it works...
See also
Adding a launch page
How to do it...
How it works...
Testing a custom controller
Getting ready
How to do it...
How it works...
See also
Testing a controller extension
How to do it...
How it works...
See also
2. Custom Components
Introduction
Passing attributes to components
How to do it...
How it works...
See also
Updating attributes in component controllers
Getting ready
How to do it...
How it works...
See also
Passing action methods to components
How to do it...
How it works...
There's more...
See also
Data-driven decimal places
How to do it...
How it works...
See also
The custom iterator component
Getting ready
How to do it...
How it works...
Setting a value into a controller property
Getting ready
How to do it...
How it works...
See also
Multiselecting related objects
Getting ready
How to do it...
How it works...
Notifying the containing page controller
Getting ready
How to do it...
How it works...
See also
3. Capturing Data Using Forms
Introduction
Editing a record in Visualforce
Getting ready
How to do it...
How it works...
See also
Adding error messages to field inputs
Getting ready
How to do it...
How it works...
See also
Adding error messages to non-field inputs
Getting ready
How to do it...
How it works...
See also
Using field sets
Getting ready
How to do it...
How it works...
Adding a custom lookup to a form
Getting ready
How to do it...
How it works...
See also
Adding a custom datepicker to a form
Getting ready
How to do it...
How it works...
See also
Retrieving fields when a lookup is populated
Getting ready
How to do it...
How it works...
Breaking up forms with action regions
Getting ready
How to do it...
How it works...
See also
The Please wait spinner
How to do it...
How it works...
Action chaining
Getting ready
How to do it...
How it works...
4. Managing Records
Introduction
Styling fields as required
Getting ready
How to do it...
How it works...
See also
Styling table columns as required
Getting ready
How to do it...
How it works...
See also
Attaching an image to a record
Getting ready
How to do it...
How it works...
There's more...
See also
Managing attachments
Getting ready
How to do it...
How it works...
There's more...
See also
Maintaining custom settings
Getting ready
How to do it...
How it works...
Refreshing record details from embedded Visualforce
Getting ready
How to do it...
How it works...
Using wrapper classes
Getting ready
How to do it...
How it works...
See also
Changing options based on the user input
Getting ready
How to do it...
How it works...
See also
Changing page layout based on the user input
Getting ready
How to do it...
How it works...
See also
Form-based searching
Getting ready
How to do it...
How it works...
See also
5. Managing Multiple Records
Introduction
Editing a record and its parent
Getting ready
How to do it...
How it works...
See also
Managing a list of records
Getting ready
How to do it...
How it works...
See also
Converting a lead
Getting ready
How to do it...
How it works...
There's more...
Managing a hierarchy of records
Getting ready
How to do it...
How it works...
See also
Inline editing a record from a list
Getting ready
How to do it...
How it works...
See also
Creating a Visualforce report
Getting ready
How to do it...
How it works...
Displaying report data in Visualforce
Getting ready
How to do it...
How it works...
Loading records asynchronously
Getting ready
How to do it...
How it works...
6. Visualforce Charts
Introduction
Creating a bar chart
Getting ready
How to do it...
How it works...
See also
Creating a line chart
Getting ready
How to do it...
How it works...
See also
Customizing a chart
Getting ready
How to do it...
How it works...
Adding multiple series
Getting ready
How to do it...
How it works...
See also
Creating a stacked bar chart
Getting ready
How to do it...
How it works...
See also
Adding a third axis
Getting ready
How to do it...
How it works...
See also
Embedding a chart in a record view page
Getting ready
How to do it...
How it works...
Multiple charts per page
Getting ready
How to do it...
How it works...
7. Enhancing the Client with JavaScript
Introduction
Using action functions
Getting ready
How to do it...
How it works...
Avoiding race conditions
Getting ready
How to do it...
How it works...
See also
The confirmation dialog
Getting ready
How to do it...
How it works...
See also
Pressing Enter to submit
Getting ready
How to do it...
How it works...
See also
The onload handler
How to do it...
How it works...
See also
Collapsible list elements
Getting ready
How to do it...
How it works...
Trapping navigation away
Getting ready
How to do it...
How it works...
See also
Creating a record using JavaScript remoting
Getting ready
How to do it...
How it works...
See also
8. Force.com Sites
Introduction
Creating a site
Getting ready
How to do it...
How it works...
See also
Record and field access
Getting ready
How to do it...
How it works...
See also
Retrieving content from Salesforce
Getting ready
How to do it...
How it works...
See also
Web to lead form
Getting ready
How to do it...
How it works...
See also
Creating a website template
Getting ready
How to do it...
How it works...
See also
Adding a header menu to a template
Getting ready
How to do it...
How it works...
See also
Adding a sidebar to a template
Getting ready
How to do it...
How it works...
See also
Conditional rendering in templates
Getting ready...
How to do it...
How it works...
See also
9. Visualforce in Salesforce1
Introduction
Navigating between pages
How to do it...
How it works...
Lightning forms
Getting ready
How to do it...
How it works...
Capturing the user's location
Getting ready
How to do it...
How it works...
Saving an image when creating a record
Getting ready
How to do it...
How it works...
See also
Capturing a signature when creating a record
Getting ready
How to do it...
How it works...
See also
Displaying a location in a map
Getting ready
How to do it...
How it works...
See also
Scanning the QR code to access the record
Getting ready
How to do it...
How it works...
10. Troubleshooting
Introduction
Avoiding validation errors with action regions
Getting ready
How to do it...
How it works...
See also
Surfacing errors
Getting ready
How to do it...
How it works...
See also
Multiple bindings to the same record
Getting ready
How to do it...
How it works...
There's more ...
Reducing view state size 1 - the transient keyword
Getting ready
How to do it...
How it works...
There's more ...
Reducing view state size 2 - HTML vs Visualforce components
Getting ready
How to do it...
How it works...
There's more ...
Debugging Visualforce
How to do it...
How it works...
There's more ...
Logging messages in a Visualforce page
Getting ready
How to do it...
How it works...
There's more
Visualforce Development Cookbook - Second Edition
Visualforce Development Cookbook - Second Edition
Copyright © 2016 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First edition: September 2013
Second edition: August 2016
Production reference: 1260816
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78646-808-6
www.packtpub.com
Credits
About the Author
Keir Bowden is a 30-year veteran of the IT industry from the United Kingdom. After spending the early part of his career in the defence industry, he moved into investment banking systems, implementing systems for Banque Nationale de Paris, CitiGroup, and Deutsche Bank. In the late 1990s, Keir moved into Internet technologies, leading to a development of the order management and payment handling systems of one of the first European Internet shopping sites.
Keir started working with Force.com in late 2008 and has been recognized multiple times by Salesforce as an MVP for his contribution and leadership in the community. In 2012, he became the first certified technical architect outside of Salesforce in EMEA, and he has served as a judge on several EMEA Technical Architect Certification Review Boards. Keir is also a prominent blogger on Apex, Visualforce and Lightning Components solutions; and a regular speaker at events such as Dreamforce, Cloud World Forum, and Salesforce World Tour.
Keir is a chief technical officer of BrightGena—a Salesforce.com Platinum Cloud Alliance Partner in the United Kingdom, where he is responsible for the present and future technical strategies.
Keir acted as a technical reviewer for the CRM Admin Cookbook before accepting the challenge of authoring this book, which also happens to be his first.
I would like to thank my partner, Marie, for putting up with me spending even more time than usual on my laptop, something that neither of us had previously thought possible. I’d also like to thank my reviewers, whose tireless efforts and attention to detail ensure that the recipes are correct and perform as expected.
About the Reviewer
Rahul Sharma has been working on the Force.com platform since 2010 and is a certified advanced developer and administrator. Currently, he is working with Cognizant and has worked on most of the areas in Salesforce. He is an active contributor to the Salesforce developer community (he holds the Pro position) and Stack Exchange. He holds a bachelors degree in electronics engineering based out of Mumbai, India. His areas of interest are UI and mobile development, along with Salesforce. He can be reached at about.me/rahuls91221.
He was a technical reviewer for the following books:
Learning Force.com Application Development
Visualforce Developer’s Guide
Mastering Application Development with Force.com
I would like to thank my family & friends for support , and Packt Publishing for giving me another opportunity to review an excellent book by our Salesforce MVP Keir Bowden.
www.PacktPub.com
For support files and downloads related to your book, please visit www.PacktPub.com.
eBooks, discount offers, and more
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at customercare@packtpub.com for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
https://www2.packtpub.com/books/subscription/packtlib
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.
Why subscribe?
Fully searchable across every book published by Packt
Copy and paste, print, and bookmark content
On demand and accessible via a web browser
Free access for Packt account holders
Get notified! Find out when new books are published by following @PacktEnterprise on Twitter or the Packt Enterprise Facebook page.
Preface
The Visualforce framework allows developers to build highly customized, personalized, and branded user interfaces for their Salesforce, Force.com, and Salesforce1 applications. Hosted natively on the Salesforce platform, Visualforce gives developers complete control over all areas of the user interface, allowing them to satisfy complex business requirements and support multiple devices.
Visualforce pages use a mixture of HTML and Visualforce components, which are processed server-side and delivered to the browser as HTML. This allows the use of standard web technologies, such as CSS and JavaScript, to provide an enriched and dynamic user experience.
The Visualforce Development Cookbook provides solutions for a variety of challenges faced by the Salesforce developers and demonstrates how easy it is to build rich interactive pages for both desktop and mobile devices using Visualforce. Each recipe contains clear, step-by-step instructions along with detailed explanations of the key areas of Visualforce, Apex or JavaScript code, that deliver the solution.
Whether you are looking to make a minor addition to the standard page functionality or override it completely, this book will provide you with practical examples that can be readily adapted to a number of scenarios.
What this book covers
Chapter 1 , General Utilities, covers enhancing or replacing standard functionality with Visualforce, systemizing business processes, guiding users through the creation and ongoing management of data, and writing effective tests.
Chapter 2, Custom Components, demonstrates how to create custom Visualforce components to encapsulate functionality for reuse across multiple pages and techniques to allow communication between component and page controllers.
Chapter 3, Capturing Data Using Forms, describes how to capture data entered in a Visualforce page and send this to the server for processing.
Chapter 4, Managing Records, offers techniques to streamline and enhance the management of Salesforce data using Visualforce pages, using styling to indicate required fields and changing pages in response to user actions.
Chapter 5, Managing Multiple Records, covers recipes to manage multiple records in a single page, ranging from editing parent and child records to managing a deep and wide hierarchy.
Chapter 6, Visualforce Charts, presents a series of recipes to create charts of increasing complexity, embed a chart into a standard Salesforce page, and add multiple charts to a single page in a similar style to a Salesforce dashboard.
Chapter 7, Enhancing the Client with JavaScript, shows how to use JavaScript to provide a variety of client-side enhancements, including confirmation of user actions, instant feedback on user inputs, and speeding up pages that access server-side data via remote methods.
Chapter 8, Force.com Sites, provides step-by-step instructions to configure a publicly accessible website styled with the Lightning Design System, allowing visitors to access the Salesforce records and extract boilerplate content to reusable templates.
Chapter 9, Visualforce in Salesforce1, demonstrates how Visualforce can be used to enhance the user experience on the Salesforce1 mobile device, including capturing the user’s location and attaching images when creating records.
Chapter 10, Troubleshooting, covers some common error scenarios and how to avoid them, along with tips to improve performance by reducing the size of the Visualforce viewstate and page load time in general.
What you need for this book
In order to build the recipes from this book, you will need an Enterprise, Unlimited or Developer (recommended) Edition of Salesforce, and System Administrator access. You will also need a supported browser, such as the latest version of Google Chrome, Mozilla Firefox, Apple Safari 8+, Internet Explorer 9+, or Microsoft Edge. Use the Setup menu to cut and paste the code samples rather than the developer console, as it may report visibility errors when the organization has a custom namespace.
Who this book is for
This book is intended for intermediate Visualforce developers who are familiar with the basics of Visualforce and Apex development on the Salesforce platform. An understanding of the basics of HTML, CSS and JavaScript is also useful for some more advanced recipes.
Sections
In this book, you will find several headings that appear frequently (Getting ready, How to do it, How it works, There's more, and See also).
To give clear instructions on how to complete a recipe, we use these sections as follows:
Getting ready
This section tells you what to expect in the recipe, and describes how to set up any software or any preliminary settings required for the recipe.
How to do it…
This section contains the steps required to follow the recipe.
How it works…
This section usually consists of a detailed explanation of what happened in the previous section.
There's more…
This section consists of additional information about the recipe in order to make the reader more knowledgeable about the recipe.
See also
This section provides helpful links to other useful information for the recipe.
Conventions
In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.
Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: Once the payment reaches the state Complete the action poller will be disabled.
A block of code is set as follows:
{!IF(AND(NOT(ISNULL(campaign.ActualCost)),
campaign.ActualCost<=campaign.BudgetedCost),
lawngreen
, red
)} value=
{!campaign.ActualCost}"/>
New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: Click on the New button.
Note
Warnings or important notes appear in a box like this.
Tip
Tips and tricks appear like this.
Reader feedback
Feedback from our readers is always welcome. Let us know what you think about this book-what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of. To send us general feedback, simply e-mail feedback@packtpub.com, and mention the book's title in the subject of your message. If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.
Customer support
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
Downloading the example code
You can download the example code files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
You can download the code files by following these steps:
Log in or register to our website using your e-mail address and password.
Hover the mouse pointer on the SUPPORT tab at the top.
Click on Code Downloads & Errata.
Enter the name of the book in the Search box.
Select the book for which you're looking to download the code files.
Choose from the drop-down menu where you purchased this book from.
Click on Code Download.
Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:
WinRAR / 7-Zip for Windows
Zipeg / iZip / UnRarX for Mac
7-Zip / PeaZip for Linux
The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Visualforce-Development-Cookbook-2e. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!
Downloading the color images of this book
We