You've reached the end of your free preview.
Want to read all 273 pages?
Unformatted text preview: Beginning
Salesforce
Developer
—
Michael Wicherski Beginning Salesforce
Developer Michael Wicherski Beginning Salesforce Developer
Michael Wicherski
Los Angeles, California, USA
ISBN-13 (pbk): 978-1-4842-3299-6 ISBN-13 (electronic): 978-1-4842-3300-9 Library of Congress Control Number: 2017962310 Copyright © 2017 by Michael Wicherski
This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the
material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation,
broadcasting, reproduction on microfilms or in any other physical way, and transmission or information
storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now
known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with
every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an
editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the
trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not
identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to
proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication,
neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or
omissions that may be made. The publisher makes no warranty, express or implied, with respect to the
material contained herein.
Cover image by Freepik ( )
Managing Director: Welmoed Spahr
Editorial Director: Todd Green
Acquisitions Editor: Susan McDermott
Development Editor: Laura Berendson
Technical Reviewer: Haulson Wong
Coordinating Editor: Rita Fernando
Copy Editor: Brendan Frost
Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street,
6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail [email protected], or visit . Apress Media, LLC is a California LLC and the sole member
(owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a
Delaware corporation.
For information on translations, please e-mail [email protected], or visit
rights-permissions.
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and
licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales
web page at .
Any source code or other supplementary material referenced by the author in this book is available to
readers on GitHub via the book's product page, located at . For more
detailed information, please visit .
Printed on acid-free paper To true friends. Table of Contents
About the Author����������������������������������������������������������������������������������������������������� xi
About the Technical Reviewer������������������������������������������������������������������������������� xiii
Acknowledgments���������������������������������������������������������������������������������������������������xv
Introduction�����������������������������������������������������������������������������������������������������������xvii
Chapter 1: Introduction to Salesforce����������������������������������������������������������������������� 1
Salesforce and the Platform��������������������������������������������������������������������������������������������������������� 1
PaaS and Multitenant Architecture����������������������������������������������������������������������������������������������� 2
Salesforce Licensing��������������������������������������������������������������������������������������������������������������������� 3
Different License Types ���������������������������������������������������������������������������������������������������������� 3
Instances and Organizations��������������������������������������������������������������������������������������������������� 6 Chapter 2: Setting Up Your Development Environment�������������������������������������������� 9
Navigating the UI������������������������������������������������������������������������������������������������������������������������� 11
Navigating the Setup UI��������������������������������������������������������������������������������������������������������� 16
Setting Up a Sandbox������������������������������������������������������������������������������������������������������������������ 18
Enabling Change Sets������������������������������������������������������������������������������������������������������������ 20
Development Environment Options�������������������������������������������������������������������������������������������� 22
The Developer Console���������������������������������������������������������������������������������������������������������� 23
IDEs��������������������������������������������������������������������������������������������������������������������������������������� 24
Bonus Setup Tips������������������������������������������������������������������������������������������������������������������� 35
Summary������������������������������������������������������������������������������������������������������������������������������������ 37 v Table of Contents Chapter 3: Structure of Data����������������������������������������������������������������������������������� 39
Objects���������������������������������������������������������������������������������������������������������������������������������������� 39
Standard Platform����������������������������������������������������������������������������������������������������������������� 40
Standard CRM������������������������������������������������������������������������������������������������������������������������ 41
Custom���������������������������������������������������������������������������������������������������������������������������������� 42
Fields������������������������������������������������������������������������������������������������������������������������������������������ 43
Default and Special�������������������������������������������������������������������������������������������������������������� 44
Calculated������������������������������������������������������������������������������������������������������������������������������ 45
Relational������������������������������������������������������������������������������������������������������������������������������� 46
Generic���������������������������������������������������������������������������������������������������������������������������������� 48
Security and Validation��������������������������������������������������������������������������������������������������������������� 50
Security��������������������������������������������������������������������������������������������������������������������������������� 50
Validation������������������������������������������������������������������������������������������������������������������������������� 52
Creating and Retrieving Data in UI���������������������������������������������������������������������������������������������� 53
Creating and Editing�������������������������������������������������������������������������������������������������������������� 53
Querying Data����������������������������������������������������������������������������������������������������������������������������� 56
SOQL�������������������������������������������������������������������������������������������������������������������������������������� 57
SOSL������������������������������������������������������������������������������������������������������������������������������������� 58
Tips and Tricks���������������������������������������������������������������������������������������������������������������������������� 59
Labels vs. API Names������������������������������������������������������������������������������������������������������������ 59
Querying Related Data���������������������������������������������������������������������������������������������������������������� 60
What’s in an ID?�������������������������������������������������������������������������������������������������������������������������� 61
Length����������������������������������������������������������������������������������������������������������������������������������� 61
Prefix������������������������������������������������������������������������������������������������������������������������������������� 61
Magic URL����������������������������������������������������������������������������������������������������������������������������������� 62
Lovable Data Summary��������������������������������������������������������������������������������������������������������������� 63 Chapter 4: Introduction to Visualforce������������������������������������������������������������������� 65
Introducing MVC�������������������������������������������������������������������������������������������������������������������������� 65
Bring On the HTML���������������������������������������������������������������������������������������������������������������������� 66
Hello HTML���������������������������������������������������������������������������������������������������������������������������������� 67
HTML Attributes�������������������������������������������������������������������������������������������������������������������������� 69
vi Table of Contents A Quick Primer on CSS���������������������������������������������������������������������������������������������������������������� 71
HTML to Visualforce�������������������������������������������������������������������������������������������������������������������� 76
Creating a Visualforce Page��������������������������������������������������������������������������������������������������� 76
Visualforce Components������������������������������������������������������������������������������������������������������������� 81
Merge Fields������������������������������������������������������������������������������������������������������������������������������� 85
Standard Controller��������������������������������������������������������������������������������������������������������������������� 87
Summary������������������������������������������������������������������������������������������������������������������������������������ 93 Chapter 5: Introduction to Apex����������������������������������������������������������������������������� 95
Apex�������������������������������������������������������������������������������������������������������������������������������������������� 95
Statements���������������������������������������������������������������������������������������������������������������������������������� 96
Comments����������������������������������������������������������������������������������������������������������������������������������� 97
Variables������������������������������������������������������������������������������������������������������������������������������������� 98
Primitive Data Types�������������������������������������������������������������������������������������������������������������� 99
Constants����������������������������������������������������������������������������������������������������������������������������� 101
Arithmetic, Concatenation, and Unary Operators����������������������������������������������������������������� 102
Composite Data Types��������������������������������������������������������������������������������������������������������� 103
Collections��������������������������������������������������������������������������������������������������������������������������� 104
Enum����������������������������������������������������������������������������������������������������������������������������������� 105
Flow Control������������������������������������������������������������������������������������������������������������������������������ 106
Logical Operators���������������������������������������������������������������������������������������������������������������� 106
Sequential��������������������������������������������������������������������������������������������������������������������������� 108
Selection������������������������������������������������������������������������������������������������������������������������������ 109
Repetition���������������������������������������������������������������������������������������������������������������������������� 113
Classes�������������������������������������������������������������������������������������������������������������������������������������� 118
Methods������������������������������������������������������������������������������������������������������������������������������� 119
Coding Conventions������������������������������������������������������������������������������������������������������������������ 124
camelCase��������������������������������������������������������������������������������������������������������������������������� 124
Names��������������������������������������������������������������������������������������������������������������������������������� 124
Classes, Methods, and Variables����������������������������������������������������������������������������������������� 125
Indentation������������������������������������������������������������������������������������������������������������������������� 126 vii Table of Contents Scope���������������������������������������������������������������������������������������������������������������������������������������� 127
Threads������������������������������������������������������������������������������������������������������������������������������������� 127
Governor Limits������������������������������������������������������������������������������������������������������������������������� 128
Script Statements���������������������������������������������������������������������������������������������������������������� 128
Heapsize������������������������������������������������������������������������������������������������������������������������������ 129
Queries�������������������������������������������������������������������������������������������������������������������������������� 129
DML������������������������������������������������������������������������������������������������������������������������������������� 129
Callouts ������������������������������������������������������������������������������������������������������������������������������� 129
Future���������������������������������������������������������������������������������������������������������������������������������� 129
A Large Sample������������������������������������������������������������������������������������������������������������������������� 130
Summary���������������������������������������������������������������������������������������������������������������������������������� 131 Chapter 6: Apex Classes and Triggers������������������������������������������������������������������ 133
Classes�������������������������������������������������������������������������������������������������������������������������������������� 133
Creating a Class������������������������������������������������������������������������������������������������������������������� 133
Methods������������������������������������������������������������������������������������������������������������������������������� 137
Utility Class�������������������������������������������������������������������������������������������������������������������������� 138
Object Class������������������������������������������������������������������������������������������������������������������������� 142
Custom Apex Controllers����������������������������������������������������������������������������������������������������� 144
Extensions��������������������������������������������������������������������������������������������������������������������������� 145
Triggers������������������������������������������������������������������������������������������������������������������������������������� 146
Insert Triggers���������������������������������������������������������������������������������������������������������������������� 152
Update��������������������������������������������������������������������������������������������������������������������������������� 162
Upsert���������������������������������������������������������������������������������������������������������������������������������� 169
Delete and Undelete������������������������������������������������������������������������������������������������������������ 171
Trigger Chains��������������������������������������������������������������������������������������������������������������������������� 172
Summary���������������������������������������������������������������������������������������������������������������������������������� 173 Chapter 7: Visualforce with Apex������������������������������������������������������������������������� 175
Custom Controllers������������������������������������������������������������������������������������������������������������������� 175
Account Manager���������������������������������������������������������������������������������������������������������������� 176
Standard Controller Extensions������������������������������������������������������������������������������������������������� 214
Developer Guides and References�������������������������������������������������������������������������������������������� 226
viii Table of Contents JavaScript with Visualforce and Apex��������������������������������������������������������������������������������������� 226
Summary���������������������������������������������������������������������������������������������������������������������������������� 227 Chapter 8: Test Coverage and Deploying�������������������������������������������������������������� 229
Test Coverage��������������������������������������������������������������������������������������������������������������������������� 229
“Bad” Test Coverage������������������������������������������������������������������������������������������������������������ 230
“Good” Test Coverage���������������������������������������������������������������������������������������������������������� 231
Test-Driven Development���������������������������������������������������������������������������������������������������� 232
Writing Tests������������������������������������������������������������������������������������������������������������������������ 233
Deploying Customization���������������������������������������������������������������������������������������������������������� 244
Deployment Checklist���������������������������������������������������������������������������������������������������������� 245
Using IDE����������������������������������������������������������������������������������������������������������������������������� 246
Using Change Sets�������������������������������������������������������������������������������������������������������������� 252
Summary��������������������������...
View
Full Document
- Summer '18
- salesforce