Book Image

Mastering Application Development with

By : Kevin J. Poorman
Book Image

Mastering Application Development with

By: Kevin J. Poorman

Overview of this book is an extremely powerful, scalable, and secure cloud platform, delivering a complete technology stack, ranging from databases and security to workflow and the user interface. With's cloud platform, you can build any business application and run it on your servers. The book will help you enhance your skillset and develop complex applications using It gets you started with a quick refresher of's development tools and methodologies, and moves to an in-depth discussion of triggers, bulkification, DML order of operations, and trigger frameworks. Next, you will learn to use batchable and schedulable interfaces to process massive amounts of information asynchronously. You will also be introduced to Salesforce Lightning and cover components—including backend (apex) controllers, frontend (JavaScript) controllers, events, and attributes—in detail. Moving on, the book will focus on testing various apex components: what to test, when to write the tests, and—most importantly—how to test. Next, you will develop a changeset and use it to migrate your code from one org to another, and learn what other tools are out there for deploying metadata. You will also use command-line tools to authenticate and access the Rest sObject API and the Bulk sObject API; additionally, you will write a custom Rest endpoint, and learn how to structure a project so that multiple developers can work independently of each other without causing metadata conflicts. Finally, you will take an in-depth look at the overarching best practices for architecture (structure) and engineering (code) applications on the platform.
Table of Contents (16 chapters)
Mastering Application Development with
About the Author
About the Reviewers

Developing for the cloud

Starting with e-mail, traditional applications for the desktop have been replaced with browser and mobile-based applications. And just like that, cloud computing has become an everyday fact of our lives. Now, you can find applications on the Web running on your browser that handle everything from photo editing and displaying to music streaming services and, of course, running your business. Corresponding to this shift to cloud-based applications, there's been a shift in how we develop software. True, we are no longer writing software on a local machine, publishing it, and having users run it on a local machine; we're now writing software on our local machine and pushing it to the App Store, the cloud, and increasingly connected devices. Salesforce development has always been somewhat different though. The Salesforce1 platform requires developers not only to run their code in the cloud, but to develop it there as well. This has always been the case to some extent, as you can't run an instance of Salesforce on your local computer. The only way to develop new features, to test, or even run your code is to put that code in the Salesforce cloud. Over the years, Salesforce has continually worked to improve this experience, first with the Eclipse-based IDE, then with the metadata and tooling APIs that facilitate third-party IDE integrations. Now, Salesforce has created the developer console, an in-browser code editor. We will use a developer console throughout the rest of this book to work through exercises, create and edit metadata, and demonstrate various features of Salesforce cloud. Before you can access the developer console, you'll need a developer edition organization. To sign up for a developer org visit the following URL. I highly encourage you to pause and sign up for the development org. Of course, if you already have a developer org, you can reuse it.

When you go to, the signup page will be displayed, as shown in the following screenshot:

Identifying the development tools

There are three main development tools for building applications. The first and perhaps the most efficient development tool is the IDE. The IDE is distributed as a plugin for the venerable Eclipse development environment. If you've done Java development, you will feel at home with this. Additionally, in the past few months, an excellent plugin for the venerable Jetbrains Intellij IDEA IDE has been released. It is called Illuminated Cloud (refer to for more information). If you're a fan of the Intellij platform, you'll feel at home with it. The Salesforce community has also established another tool called MavensMate for developing Salesforce1 applications. MavensMate is a set of plugins for the excellent sublime text and the atom text editors. The plugins use the metadata and tooling APIs to provide a rich set of development tools. These tools include logging, anonymous apex execution, and the creation and editing of metadata. Documentation on installation and use of the MavensMate plugin can be found at the MavensMate home page, The developer console is a relatively new feature to Salesforce. It provides an in-browser tool for developers to create and edit metadata, as well as run tests, execute queries, and generally inquire into the state of your application code. You can access the developer console by clicking on your name in the upper right-hand corner of the screen and selecting developer console, as shown here:

At various points, you'll see text items denoted by the pipe symbol( | ), for example, File | New | Class.

Let's take a look at the following screenshot of menu instructions for the developer console:

For example, if you click on the File menu, followed by the new menu item, and finally on the class menu item, you'll be given an opportunity to create, name, and create a new Apex class:

Object-oriented building blocks of development

The Salesforce1 platform runs the Apex programming language. Like most other contemporary programming languages, Apex is object-oriented. Object-oriented development is focused on the creation of and interaction between objects. Objects are the result of instantiating classes. Classes describe properties and methods that can be interacted with. For instance, you might have a Box class, with properties of height, width, and depth. A box object would refer to a specific instance of the class box, with it's own values for height, width, and depth. Classes are the basic building blocks of object-oriented development and, therefore, development. Classes come in many varieties, from Visualforce controllers and controller extensions to inner and wrapper classes and normal classes. We will work with a number of class types throughout the book. Each class type can be created via the developer console using the new class option in the file menu and giving it a name.

While classes are building blocks of object-oriented development in the Salesforce1 ecosystem, there are a couple of other code containers, specifically, triggers and lightning bundles. Aside from where the files are stored, the biggest difference between classes and triggers is found in their first line. Classes use the class keyword, whereas triggers use the Trigger keyword:

//Definition of a class
Public with sharing class myExampleClass {
//Definition of a Trigger
Trigger myExampleTrigger on Account (before insert) {

Triggers differ from classes in that they define reflexive behavior that the system takes in response to certain data manipulation actions. Triggers have their own rules and ecosystems, and we will look at them in detail in their own Chapter 2, Architecting Sustainable Triggers using a Trigger Framework. Lightning Bundles, on, on the other hand contain more than just code. Lightning bundles also contain other assets like CSS style definitions, icons and documentation.

Learning to master Salesforce1 development

There is an old story about a new developer and a seasoned developer tackling the same problem. The new programmer Googles the problem, and after looking at a few stack exchange posts, pastes together some code and is confident that it works. After all, he thinks, other people have this exact same problem and they helpfully posted their results online. With their help, the new developer can put together a solution. On the other hand, the experienced developer first sits down and writes a test to prove that the problem exists. Only then does the developer write code to try to rectify it. This is one of the key differences between being an application developer and a master application developer. This is equally true for Salesforce1 platform. To truly master the platform, you not only need to know the language, logic, and patterns, but also how to know, objectively, when the code is done. Because of this, we'll be focusing on writing automated tests for our code.

Knowing when your code works is paramount to Apex solutions. However, the Salesforce1 platform provides a number of ways to develop solutions without writing Apex. Almost everything that can be done with the declarative tools can be done with Apex code, but to master the platform, you need to know when to use those declarative tools and when to write Apex.