Visualforce in Practice

Visualforce in Practice

Michael Floyd Don Robins Matt Lacey Michael Topalovich Dan Appleman and Lior Gotersman Ryan Sieve Peter Gruhl

i

Copyrights

? Copyright 2000?2013 , inc. All rights reserved. is a registered trademark of , inc., as are other names and marks. Other marks appearing herein may be trademarks of their respective owners. Various trademarks held by their respective owners.

No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form, or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior consent of the publisher.

Written by Michael Floyd, Don Robins, Michael Topalovich, Dan Appleman and Lior Gotersman, Ryan Sieve and Peter Gruhl.

Contributions by Pat Patterson, Sandeep Bhanot, Raja Rao DV, and Michael Alderete.

Cover by Domenique Sillett.

Special Thanks to Nick Tran, Adam Seligman, Quinton Wall, Andrew Waite, Chris Wall, and Lesley Schneiderman.

ii

Introduction

The making of this book is an interesting story. The seed of its inspiration came from developers like you. Following one of our ELEVATE Workshops, an attendee was asked what he would like to see next. He simply replied "A book about Visualforce."

Then my colleague Mario Korf spoke up, saying that "We have an Advanced Apex book," authored by Dan Appleman to compliment our Introductory Apex Developer's Guide. "We should do an Advanced Visualforce." And that's how this book was born.

But rather than follow the Beginner-Advanced documentation model, I wanted a book that shows developers how to do real things while learning through actual apps that have been deployed and are in practice. This is Visualforce in Practice.

I also wanted readers to get the opportunity to learn from practitioners, developers in the trenches that are earnestly building enterprise applications and deploying them to the cloud. I wanted to share the experience of those who have gone before you.

And so I recruited Don Robins, a veteran Certified Salesforce Trainer and Salesforce MVP--the only developer to hold both titles. With Don's help we recruited Matt Lacey, Michael Topalovich, Dan Appleman, Lior Gotesman, Ryan Sieve and Peter Gruhl.

Together we've assembled a collection of Visualforce example apps that you can use in your own practice. This is not documentation, and it is not intended to document every feature built into Visualforce. This book is intended to share the experience and expertise of our authors.

About the Book

Visualforce in Practice is intended for intermediate developers. The book assumes you have walked through the Visualforce Workbook tutorial, and know the basics of creating a Visualforce page.

Chapter 1, Thinking in Visualforce lays the groundwork by discussing the MVC design Pattern, when you should use Visualforce and alternatives for using Visualforce under various use cases.

The Standard Controller is an amazingly versatile component that changes behavior based on the objects it's working on. In that sense it is a polymorphic component that can do an amazing amount of work without having to write code. In Chapter 2, Don Robins walks you through the Standard Controller and sheds light on mysterious components like URLFOR().

Because you'll need to write custom controllers or controller extensions at some point, Chapter 4 introduces you to "Just Enough Code." Rather than providing introductions to Apex and SOQL, this chapter gives you the basics so you can get started writing controllers and extensions immediately.

In Part II the rubber meets the road with chapters that will show you how to work with and paginate lists using the StandardSetController (Chapter 4), and how to create wizards that walk users through a process (Chapter 5). Chapter 6 shows how to create amazing looking charts

iii

to display data using the Analytics API, and Chapter 7 walks through the process for creating dashboards.

Chapter 8 uses the Streaming API to stream live data into Visualforce pages, while Chapter 9 shows how to build Visualforce page templates like those in the Salesforce Mobile Templates. Chapter 10 shows you how to add JavaScript and HTML5 to your Visualforce pages, which sets up Part III covering mobile development.

Chapter 11 walks you through the process of refactoring existing apps, then extends to mobile the Warehouse App used in the Workbook. Chapter 12 introduces you to the Salesforce Mobile Templates, the brainchild of Developer Evangelist Sandeep Bhanot. And Finally Chapter 13 presents readers with tips and tricks for optimizing Visualforce pages to ensure peek performance.

Looking back, there are many topics we would like to have covered in this book, and with the introduction of Salesforce1 there are many new topics we would like to include in the future. Indeed, I'm looking forward to creating a second edition of Visualforce in Pracice. In the meantime, it is my sincerest hope that you find this book not only educational, but useful in your everyday practice.

Sincerely,

Michael Floyd Editor in Chief, Developer Force

iv

Contents

Introduction................................................................................................................................... ii About the Book............................................................................................................................. iii

Chapter 1--Thinking in Visualforce...........................................................................9

What is Visualforce...................................................................................................................... 10 Controllers and Extensions......................................................................................................... 10 About the Markup....................................................................................................................... 11 About View State......................................................................................................................... 11 What is Contained in the View State?......................................................................................... 12 Examining the View State............................................................................................................ 12 View State in Action.................................................................................................................... 13 New Addition to Visualforce....................................................................................................... 16 Salesforce1 and Visualforce......................................................................................................... 16 Five Things you should master before getting startted with Visualforce................................... 16 Parting Words.............................................................................................................................. 18

Chapter 2--The Standard Controller--Pushing the Envelope........................ 19

What Is a Standard Controller?................................................................................................... 21 What Does a Standard Controller Do?....................................................................................... 21 CONTROLLING VIEWS............................................................................................................ 22 Materializing a User Interface..................................................................................................... 22 Standard User Interface Flow...................................................................................................... 23 CONTROLLING DATA.............................................................................................................. 24 Referencing a Single Record........................................................................................................ 24 Loading Field Values................................................................................................................... 25 Loading Field Values in Apex...................................................................................................... 26 Referencing a List of Records...................................................................................................... 27 CONTROLLING ACTIONS AND NAVIGATION................................................................... 28 Actions as Navigation.................................................................................................................. 28 Stateful Actions............................................................................................................................ 28 Stateful Action Mechanisms........................................................................................................ 29 Demo Custom sObject Actions................................................................................................... 31 Stateless Actions........................................................................................................................... 31 Stateless Action Mechanisms....................................................................................................... 33 $Action Global Variable.............................................................................................................. 33

1

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download