in implementation guides ~ read.
Extend Code

Extend Code

DOWNLOAD

First things first !
To download this implementation guide, click the download button below.
If you need more information about the implementation guide, you can read the Table of Contents below.

Download

Enhance Salesforce with Code
Salesforce Spring

salesforcedocs
Last updated February

Copyright salesforcecom inc All rights reserved Salesforce is a registered trademark of salesforcecom inc

as are other names and marks Other marks appearing herein may be trademarks of their respective owners

CONTENTS

Enhance Salesforce with Code
Writing Code
Debugging Your Code
Testing Your Changes
Managing Scratch Orgs

Index

ENHANCE SALESFORCE WITH CODE

You can make your Salesforce org even more useful and responsive to your users by developing custom applications and integrating
your external applications
Its best to do your development in a sandbox so you can test your code changes before you deploy them Sandboxes contain copies
of your data code and configuration settings that are isolated from your production environment You can customize your organization
and test applications in a sandbox then deploy the changes to your production organization when ready In some cases you might
have several developers working in different sandboxes who then coordinate those changes for deployment
Writing Code
Write code using the Apex programming language to add business logic or use the Visualforce markup language to create the user
interface Integrate your application using APIs and authenticate your external applications
Debugging Your Code
Use checkpoints logs and the View State tab to help debug the code youve written
Testing Your Changes
Testing is key to the success of your application particularly if you deploy your application to customers If you validate that your
application works as expected with no unexpected behavior your customers are going to trust you more
Managing Scratch Orgs
The scratch org is a sourcedriven and disposable deployment of Salesforce code and metadata made for developers and automation

A scratch org is fully configurable allowing developers to emulate different Salesforce editions with different features and preferences

Scratch orgs are a central feature of Salesforce DX an open developer experience for developing and managing Salesforce apps

across their entire lifecycle

SEE ALSO

Sandbox Types and Templates
Complete Salesforce Developer Documentation

Writing Code
Write code using the Apex programming language to add business logic or use the Visualforce markup language to create the user
interface Integrate your application using APIs and authenticate your external applications
Salesforce Development Tools
Salesforce provides various tools for all phases of app development
Developer Console
The Developer Console is an integrated development environment with a collection of tools you can use to create debug and test
applications in your Salesforce org
Working with Code
This section contains information about the tools and techniques you can use when making changes to your organization by using
code

Enhance Salesforce with Code

Salesforce Development Tools

Canvas App Previewer
Canvas App Previewer is a development tool that lets you see what your canvas apps will look like before you publish them

SEE ALSO

Debugging Your Code
Testing Your Changes
Securing Your Code

Salesforce Development Tools
Salesforce provides various tools for all phases of app development

EDITIONS

This table summarizes the functionality of the various Salesforce development tools
Tool

Code

Debug Test

Deploy Available From

Salesforce Extensions for VS Code

Visual Studio Code
Marketplace

Salesforce CLI

developersalesforcecom

Developer Console

Your Name or the

Available in Salesforce
Classic not available in all
orgs
The available tools vary
according to which
Salesforce Edition you have

quick access menu

Forcecom IDE

developersalesforcecom

Visualforce development mode
footer

Setup or your personal
settings

Code editor

Setup

Apex Test Execution

Setup

Change Sets

Setup

Ant Migration Tool

developersalesforcecom

Note Forcecom IDE is a free resource provided by Salesforce to support its users and partners but is not considered part of our

Services for purposes of the Salesforce Master Subscription Agreement

SEE ALSO

Developer Console Functionality
Choose Your Tools for Developing and Deploying Changes
Enable Development Mode
Personalize Your Salesforce Experience

Enhance Salesforce with Code

Developer Console

Developer Console
The Developer Console is an integrated development environment with a collection of tools you can use to create debug and test
applications in your Salesforce org
Open the Developer Console
It takes only a couple of clicks to open the Developer Console from Salesforce Classic or Lightning Experience The Developer Console
is an integrated development environment with a collection of tools you can use to create debug and test applications in your
Salesforce org
Developer Console Functionality
The Developer Console can help with many of your development tasks
Developer Console Query Editor

You can use the Query Editor in the Developer Console to execute a SOQL query or SOSL search on the data in your organization

The History pane displays your last queries for quick reuse Results are displayed in a Query Results grid in which you can open

create update and delete records For SOSL search results with multiple objects each object is displayed on a separate tab

The Developer Console User Interface
The Developer Console includes a collection of useful tools for coding debugging and testing applications

Open the Developer Console

USER PERMISSIONS

EDITIONS

To use the Developer Console

API Enabled AND View All Data

To view retain and delete debug logs

View All Data

To execute anonymous Apex

Author Apex

To use code search and run SOQL or SOSL

on the query tab

API Enabled

To save changes to Apex classes and
triggers

Author Apex

To save changes to Visualforce pages and
components

Customize Application

To save changes to Lightning resources

Customize Application

Available in Salesforce
Classic not available in all
orgs and Lightning
Experience
Available in Enterprise
Performance Unlimited
Developer and
Databasecom Editions

It takes only a couple of clicks to open the Developer Console from Salesforce Classic or Lightning Experience The Developer Console
is an integrated development environment with a collection of tools you can use to create debug and test applications in your Salesforce
org
To open the Developer Console from Salesforce Classic
Click Your Name
Click Developer Console
To open the Developer Console from Lightning Experience

Click the quick access menu

Enhance Salesforce with Code

Developer Console

Click Developer Console

Developer Console Functionality

USER PERMISSIONS

EDITIONS

To use the Developer Console

API Enabled AND View All Data

To view retain and delete debug logs

View All Data

To execute anonymous Apex

Author Apex

To use code search and run SOQL or SOSL

on the query tab

API Enabled

To save changes to Apex classes and
triggers

Author Apex

To save changes to Visualforce pages and
components

Customize Application

To save changes to Lightning resources

Customize Application

Available in Salesforce
Classic not available in all
orgs and Lightning
Experience
Available in Enterprise
Performance Unlimited
Developer and
Databasecom Editions

The Developer Console can help with many of your development tasks

What Tasks Can You Accomplish with the Developer Console
Debugging and Troubleshooting
The Developer Console provides a convenient set of tools for efficiently tracking down logical issues
View Logs Use the Logs tab to view a list of logs Open logs in the Log Inspector Log Inspector is a contextsensitive execution
viewer in the Developer Console It shows the source of an operation what triggered the operation and what occurred next Use
this tool to inspect debug logs that include database events Apex processing workflow and validation logic
Set and View Checkpoints in Apex Code Use the Developer Console to set checkpoints to identify the source of errors For
example if you want to understand why a certain request generates an error you can review the execution identify the offending
logic and set a checkpoint When you execute the process again you can inspect the request at that specific point to understand
in detail how to improve your code While the Developer Console cant pause execution like a traditional debugger it provides cloud
developers much of the same visibility and reduces the need to instrument code with Systemdebug commands
Editing and Navigating Source Code
The Developer Console allows you to browse open edit and create source code files
Browse Packages in Your Organization Navigate the contents of packages created in your organization
View and Edit Apex Classes and Triggers Open and edit Apex triggers and classes and open a readonly view of your custom
object definitions
View and Edit Lightning Components Open and edit Lightning resources such as an application component event or interface
View and Edit Visualforce Pages and Components Open and edit Visualforce pages and components
Use the Source Code Editor Open a working set of code files and switch between them with a single click The Developer Console
Source Code Editor includes an autocomplete feature for Apex code
Testing and Validating Performance

Enhance Salesforce with Code

Developer Console

The Developer Console has a number of features dedicated to testing code and analyzing performance
Test Apex Code Use the Developer Console to check code coverage and run Apex tests including unit tests functional tests
regression tests and so on To facilitate the development of robust errorfree code Apex supports the creation and execution of
unit tests Unit tests are class methods that verify whether a particular piece of code is working properly Unit test methods take no
arguments commit no data to the database send no emails and are flagged with the testMethod keyword or the isTest
annotation in the method definition Also test methods must be defined in test classes that is classes annotated with isTest
Inspect Logs for Performance Issues Log Inspector is a contextsensitive execution viewer in the Developer Console It shows
the source of an operation what triggered the operation and what occurred next Use this tool to inspect debug logs that include
database events Apex processing workflow and validation logic Open a debug log and view the aggregated performance of an
operation in the Performance Tree The Executed Units panel breaks up the request both by time and type and categorizes the

timings by methods queries workflows callouts DML validations triggers and pages giving you a clear idea of where to find

performance issues Use the Timeline panel to see a timeline view of the overall request and walk through the events for a given
block The Limits panel provides a summary view of resources used and maps them against your allocated request limits

Executing SOQL and SOSL Queries

The Developer Console provides a simple interface for managing SOQL and SOSL queries

Edit and Execute SOQL and SOSL Queries Use the Query Editor to query data from your organization

View Query Results Results are displayed in a Query Results grid in which you can open create update and delete records For

SOSL search results with multiple objects each object is displayed on a separate tab

SEE ALSO

Open the Developer Console
The Developer Console User Interface
Developer Console File Menu
Logs Tab
Examples of Using the Log Inspector

Developer Console Query Editor

You can use the Query Editor in the Developer Console to execute a SOQL query or SOSL search on the data in your organization The

History pane displays your last queries for quick reuse Results are displayed in a Query Results grid in which you can open create

update and delete records For SOSL search results with multiple objects each object is displayed on a separate tab

Enhance Salesforce with Code

Developer Console

Execute a SOQL Query or SOSL Search

Execute SOQL queries or SOSL searches in the Query Editor panel of the Developer Console

Retrieve Query Plans

Use the Query Plan tool to optimize and speed up queries done over large numbers of records View query plans for SOQL queries

SOSL searches reports and list views If custom indexes are available for your organization use query plans to help you decide when

to request a custom index from Salesforce Support
Query Results Grid
The Query Results grid displays each record as a row You can create update and delete records without leaving the Developer

Console For SOSL search results with multiple objects each object is displayed on a separate tab

SEE ALSO

Developer Console Functionality

Execute a SOQL Query or SOSL Search

Execute SOQL queries or SOSL searches in the Query Editor panel of the Developer Console

Enter a SOQL query or SOSL search in the Query Editor panel

If you want to query tooling entities instead of data entities select Use Tooling API

Click Execute If the query generates errors they are displayed at the bottom of the Query Editor panel Your results display in the
Query Results grid in the Developer Console workspace

Warning If you rerun a query unsaved changes in the Query Results grid are lost
To rerun a query click Refresh Grid or click the query in the History panel and click Execute

Enhance Salesforce with Code

Developer Console

For information on query and search syntax see the SOQL and SOSL Reference

SEE ALSO

Developer Console Query Editor
Retrieve Query Plans
Query Results Grid

Retrieve Query Plans

Use the Query Plan tool to optimize and speed up queries done over large numbers of records View query plans for SOQL queries SOSL

searches reports and list views If custom indexes are available for your organization use query plans to help you decide when to request
a custom index from Salesforce Support
To enable the Query Plan button in the Query Editor click Help Preferences set Enable Query Plan to true and then click Save

To get Query Plans for SOQL queries or SOSL searches enter your query and click the Query Plan button in the Query Editor

The Query Plan window displays all query operations and the cost of each The Notes pane displays all notes that are available for your
highest ranked query plan which is the query plan thats currently in use
To view query plans for reports or list views complete these steps

Find the ID of your report or list view in its URL

Enter the report or list view ID in the Query Editor and then click Query Plan

Inspect the query plan for your report or list view

SEE ALSO

Developer Console Query Editor

Execute a SOQL Query or SOSL Search

Query Results Grid

Query Results Grid
The Query Results grid displays each record as a row You can create update and delete records without leaving the Developer Console

For SOSL search results with multiple objects each object is displayed on a separate tab

To open a record in the results click the row and click Open Detail Page To edit the record click Edit Page to jump to the record
in Salesforce
To create a record click Insert Row Enter the information and click Save Rows

Enhance Salesforce with Code

Developer Console

Note To insert a row the query results must contain all the required fields for the object The required fields must be simple
text or number fields If these conditions arent met a blank row is created but you cant save it In this case click Create New
to create a record in Salesforce
To edit a record within the Query Results grid doubleclick the row Make your changes and click Save Rows
To delete a record select the related row and click Delete Row

SEE ALSO

Developer Console Query Editor

Execute a SOQL Query or SOSL Search

Retrieve Query Plans

The Developer Console User Interface
The Developer Console includes a collection of useful tools for coding debugging and testing applications

The Developer Console is organized into these sections
Menubar
Workspace with a tab for each open item
Logs Tests and Problems panel

Tip To see a list of Developer Console keyboard shortcuts click Help Shortcut Keys or press CTRLSHIFT

Enhance Salesforce with Code

Developer Console

Developer Console User Interface Menu Bar
The menu bar contains menus that give you access to most of the important functionality
Developer Console User Interface Workspace

A workspace is a collection of resources represented by tabs in the main panel of the Developer Console The detail view or editor

shown in each tab is determined by the type of resource open in the tab For example source code opens in the Source Code Editor
logs open in the Log Inspector and so on
Developer Console User Interface Logs Tests and Problems Panel
The lower panel in the Developer Console includes a collection of useful tabs
Developer Console Command Line Reference
The Developer Console includes a command line for various useful commands To open or close the Developer Console Command

Line Window press CTRLSHIFTL

SEE ALSO

Developer Console Functionality

Developer Console User Interface Menu Bar
The menu bar contains menus that give you access to most of the important functionality
The Help menu includes links to the online help a reference page of shortcut keys and the Developer Console preferences page
Developer Console File Menu
The Developer Console File menu allows you to manage your Apex triggers and classes Visualforce pages and components and

static resources text XML JavaScript or CSS It includes these options

Open Types with the File Open Window
You can browse and open your application code and data objects from the Developer Console Open window
Developer Console Edit Menu
The Developer Console Edit menu allows you to search and edit your code files It includes these options
Developer Console Debug Menu
The Developer Console Debug menu allows you to manage your logs and execute anonymous Apex It includes these options

Developer Console File Menu
The Developer Console File menu allows you to manage your Apex triggers and classes Visualforce pages and components and static

resources text XML JavaScript or CSS It includes these options

New Creates a resource and opens it in the Source Code Editor You can create these resources
Apex class or trigger To create an Apex trigger first select the object to associate with the trigger
Lightning application component event interface or tokens bundle For more information see Lightning Component Framework
on page
Visualforce page or component

Static resource file text XML JavaScript or CSS

Open Launches a File Open window that allows you to browse and open your application code and data objects
Open Resource Launches an Open Resource window that allows you to search for files by name

Enhance Salesforce with Code

Developer Console

Open Lightning Resources Launches an Open Lightning Resources window that allows you to search for Lightning components
resources by name
Open Log Opens the selected log in the Log Inspector You can also access logs from the Logs tab
Open Raw Log Opens the selected log in plain text
Download Log Saves a text copy of the selected log to your local machine
Save Saves the item in the active tab
Save All Saves changes in all the tabs open in your workspace Use this option to save a set of dependent changes
Delete Deletes the item in the active tab You can only delete Apex classes triggers Visualforce pages and static resource files
Close Closes the active tab
Close All Closes all the tabs open in your workspace If any tab contains unsaved changes you are prompted to save them

Note As of API version you can build Lightning components using two programming models Lightning Web Components

and the original model Aura Components Lightning web components are custom HTML elements built using HTML and modern

JavaScript Lightning web components and Aura components can coexist and interoperate on a page You cannot develop
Lightning web components in the Developer Console

SEE ALSO

Open Types with the File Open Window
Source Code Editor
Object Inspector

Open Types with the File Open Window
You can browse and open your application code and data objects from the Developer Console Open window

To navigate to an item in the Open window
In the Setup Entity Type column click the type of the item you want to find
In the Entities column scroll and find the item to examine
To filter the displayed items click the Filter text box and enter the filter criteria to match
To see related items in the Related column click the item once
For example click an object to see the Apex classes that use it
To open the item in a new tab doubleclick it or select it and click Open
Code files open in the Source Code Editor while data objects open in Object Inspector view

Enhance Salesforce with Code

Developer Console

You can browse and open the contents of packages in your org in the File Open window You can see the complete contents of
packages and open the code files and custom objects contained in a package You can see package items such as custom fields and
validation rules in the list but you cant view them in detail
Note You cant view or edit the contents of managed packages that youve installed in your org You can browse open and edit
the classes objects and other entities in your installed unmanaged packages as if you had created those entities yourself
The Packages entity type includes only packages that youve created not managed or unmanaged packages that youve installed

SEE ALSO

Source Code Editor
Log Inspector
Object Inspector

Developer Console Edit Menu
The Developer Console Edit menu allows you to search and edit your code files It includes these options
Find Searches the current view for the selected text If no text is selected opens a browser find dialog
Find Next Finds the next match for the selected or specified text in the current view
FindReplace Finds and replaces the selected or specified text in the current view
Search in Files Opens a search dialog to search the contents of all code files
Fix Indentation Corrects the indentation in the current code file

Developer Console Debug Menu
The Developer Console Debug menu allows you to manage your logs and execute anonymous Apex It includes these options
Open Execute Anonymous Window Opens a new window that allows you to enter Apex code for testing See Executing Anonymous
Apex Code
Execute Last Executes the most recent entry in the Enter Apex Code window
Switch Perspective Selects the perspective from the list of available standard and custom perspectives See Log Inspector
View Log Panels Displays a list of available panels for use in a perspective
Perspective Manager Opens the Perspective Manager See Managing Perspectives in the Log Inspector
Save Perspective Saves any changes youve made to the current perspective since it was open
Save Perspective As Saves a copy of the current perspective with a different name
AutoHide Logs Select this option to clear existing logs when the page is refreshed
Show My Current Logs Only Deselect this option selected by default to see all logs saved for your organization including newly
generated logs created by other users
Show My Current Checkpoints Only Deselect this option selected by default to display all checkpoints currently saved for your
organization including newly generated ones created by other users
Clear Select Log Panel Checkpoint Results Panel or Checkpoint Locations to erase current data from the cache and refresh
the display
Resume Updating Renews the connection to the server This option is only shown if polling has been interrupted due to inactivity
Change Log Levels Opens the log settings dialog to define logging levels for future requests See Debug Log Levels

***