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 Summer

PREVIEW

Note This release is in preview Features described in this document dont become generally available
until the latest general availability date that Salesforce announces for this release Before then and where
features are noted as beta pilot or developer preview we cant guarantee general availability within
any particular time frame or at all Make your purchase decisions only on the basis of generally available
products and features

salesforcedocs
Last updated April

Copyright Salesforce Inc All rights reserved Salesforce is a registered trademark of Salesforce Inc as are other

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

CONTENTS

Enhance Salesforce with Code
Work With APIs
Write Code
Debug Your Code
Test Your Changes
Manage 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
Work With APIs
Salesforce provides programmatic access to your orgs information using simple powerful and secure application programming
interfaces
Write 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
Debug Your Code
Use checkpoints logs and the View State tab to help debug the code youve written
Test 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
Manage Scratch Orgs
The scratch org is a sourcedriven and disposable deployment of Salesforce code and metadata made for developers and automation

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

preferences

SEE ALSO

Sandbox Types and Templates
Complete Salesforce Developer Documentation

Work With APIs
Salesforce provides programmatic access to your orgs information using simple powerful and secure application programming interfaces

Which API Do I Use

Choose the right Salesforce API for your integration needs Review the selection of APIs Salesforce offers including the supported

protocols data formats and use cases

Enhance Salesforce with Code

Which API Do I Use

Give Integration Users API Only Access

Following the principle of least privilege we recommend creating and configuring one Salesforce user for every integration Assigning

a different user to each calling system use case domain or API resource restricts those users to a unique subset of data Creating

dedicated integration users gives you more control over operations and traceability of transactions and minimizes the impact if a
user or integration is compromised

Download API WSDL and Client Certificates

To integrate your applications with Salesforce using the API download a Web Services Description Language WSDL document

Manage API Usage Notifications

When you create a request usage notification you specify an administrator to receive an email notification whenever your organization

exceeds a specified limit for the number of API requests made in a specified span of hours

SEE ALSO

Write Code
Debug Your Code
Test Your Changes
Secure Your Code

Which API Do I Use

Choose the right Salesforce API for your integration needs Review the selection of APIs Salesforce

offers including the supported protocols data formats and use cases

API Name

API Type

Data Format

Communication

REST API

REST

JSON XML

Synchronous

SOAP API

SOAP WSDL

XML

Synchronous

Connect REST API

REST

JSON XML

Synchronous
photos are
processed
asynchronously

Apex REST API

REST

JSON XML Custom Synchronous

Apex SOAP API

SOAP WSDL

XML

Synchronous

Analytics REST API

REST

JSON XML

Synchronous

User Interface API

REST

JSON

Synchronous

GraphQL API

GraphQL

JSON

Synchronous

Tooling API

REST or SOAP

WSDL

JSON XML Custom Synchronous

Bulk API

REST

CSV

Asynchronous

Metadata API

SOAP WSDL

XML

Asynchronous

PubSub API

gRPC and protocol

buffers

Binary

Asynchronous

EDITIONS

Available in Salesforce
Classic not available in all
orgs and Lightning
Experience
Available in Professional

with API access enabled

Enterprise Performance
Unlimited and Developer
Editions

USER PERMISSIONS

To use the APIs

API Enabled

To use Apex classes and

methods as REST web

services
Note Enables access

to Apex REST services

even if API Enabled

permission is not
granted

Apex REST Services

Enhance Salesforce with Code

Which API Do I Use

When to Use REST API

REST API provides a powerful convenient and simple RESTbased web services interface for interacting with Salesforce Its advantages

include ease of integration and development and its an excellent choice of technology for use with mobile applications and web

projects For certain projects you can use REST API with other Salesforce REST APIs To build UI for creating reading updating and

deleting records including building UI for list views actions and dependent picklists use User Interface API To build UI for BB Commerce

on Lightning CMS managed content Experience Cloud sites or Chatter use Connect REST API If you have many records to process

consider using Bulk API which is based on REST principles and optimized for large sets of data

See REST API Developer Guide

When to Use SOAP API

SOAP API provides a powerful convenient and simple SOAPbased web services interface for interacting with Salesforce You can use

SOAP API to create retrieve update or delete records You can also use SOAP API to perform searches and much more Use SOAP API

in any language that supports web services

For example you can use SOAP API to integrate Salesforce with your orgs ERP and finance systems You can also deliver realtime sales

and support information to company portals and populate critical business systems with customer information

See SOAP API Developer Guide

When to Use Connect REST API

Connect REST API provides programmatic access to BB Commerce for Lightning CMS managed content Experience Cloud sites files

notifications topics and more Use Connect REST API to display Chatter feeds users and groups especially in mobile applications

See Connect REST API Developer Guide

When to Use Apex REST API

Use Apex REST API when you want to expose your Apex classes and methods so that external applications can access your code through

REST architecture Apex REST API supports both OAuth and Session ID for authorization

See Apex Developer Guide Exposing Apex Classes as REST Web Services

When to Use Apex SOAP API

Use Apex SOAP API when you want to expose Apex methods as SOAP web service APIs so that external applications can access your

code through SOAP

Apex SOAP API supports both OAuth and Session ID for authorization

See Apex Developer Guide Exposing Apex Methods as SOAP Web Services and SOAP API Developer Guide ApexRelated Calls

When to Use Analytics REST API

You can access CRM Analytics assets such as datasets lenses and dashboards programmatically using the Analytics REST API Send

queries and access datasets that have been imported into the analytics platform Create and retrieve lenses Access XMD information

Retrieve a list of dataset versions Create and retrieve CRM Analytics apps Create update and retrieve dashboards Retrieve a list of

dependencies for an application Determine what features are available to the user Work with snapshots Manipulate replicated datasets

See Analytics REST API Developer Guide

Enhance Salesforce with Code

Which API Do I Use

When to Use User Interface API

Build Salesforce UI for native mobile apps and custom web apps using the same API that Salesforce uses to build Lightning Experience

and Salesforce for Android iOS and mobile web Build user interfaces that let users work with records list views actions favorites and

more Not only do you get data and metadata in a single response but the response matches metadata changes made to the org by
Salesforce admins You dont worry about layouts picklists fieldlevel security or sharingall you do is build an app that users love

See User Interface API Developer Guide

When to Use GraphQL API

Build highly responsive and scalable apps by returning only the data a client needs all in a single request GraphQL API overcomes the

challenges posed by traditional REST APIs through field selection resource aggregation and schema introspection Field selection

reduces the size of the payload sending back only fields that were included in the query Aggregations reduce round trips between the
client and server returning a set of related resources within a single response Schema introspection enables a user to see the types
fields and objects that the user has access to

See GraphQL API Developer Guide

When to Use Tooling API

Use Tooling API to integrate Salesforce metadata with other systems Metadata types are exposed as sObjects so you can access one

component of a complex type This fieldlevel access speeds up operations on complex metadata types You can also build custom

development tools for Forcecom applications For example use Tooling API to manage and deploy working copies of Apex classes and

triggers and Visualforce pages and components You can also set checkpoints or heap dump markers execute anonymous Apex and
access logging and code coverage information

REST and SOAP are both supported

See Tooling API

When to Use Bulk API

Use Bulk API to query queryAll insert update upsert or delete a large number of records asynchronously Bulk API is designed

on the Salesforce REST framework

Any data operation that includes more than records is a good candidate for Bulk API to successfully prepare execute and

manage an asynchronous workflow that uses the Bulk framework Jobs with fewer than records should involve bulkified synchronous

calls in REST for example Composite or SOAP

When working with large volumes of data its the easiest way to create read update and delete CRUD records at scale If your job

includes just one sObject type or extracts up to TB of data per day Bulk API is your Salesforce API of choice

See Bulk API and Bulk API Developer Guide

When to Use Metadata API

Use Metadata API to retrieve deploy create update or delete customizations for your org The most common use is to migrate changes

from a sandbox or testing org to your production environment Metadata API is intended for managing customizations and for building

tools that can manage the metadata model not the data itself

The easiest way to access the functionality in Metadata API is to use the Salesforce Extensions for Visual Studio Code or Salesforce CLI

Both tools are built on top of Metadata API and use the standard tools to simplify working with Metadata API

Enhance Salesforce with Code

Give Integration Users API Only Access

The Salesforce Extensions for Visual Studio Code includes tools for developing on the Salesforce platform in the lightweight extensible

VS Code editor These tools provide features for working with development orgs scratch orgs sandboxes and DE orgs Apex Aura

components and Visualforce

Salesforce CLI is ideal if you use scripting or the command line for moving metadata between a local directory and a Salesforce org

See Metadata API Developer Guide

When to Use PubSub API

You can use Pub Sub API to integrate external systems with events Event streams are based on custom payloads through platform

events or changes in Salesforce records through Change Data Capture In Salesforce you can publish and subscribe to events with Apex
triggers Process Builder and Flow Builder

PubSub API is built for high scale bidirectional event integration with Salesforce Use PubSub API to efficiently publish and subscribe

to binary event messages in the Apache Avro format PubSub API is based on gRPC and HTTP and uses a pullbased model so that

you can control the subscription flow With PubSub API you can use one of the programming languages that gRPC supports

Use the type of streaming event that suits your needs
Change Data Capture Event
Receive changes to Salesforce records with all changed fields Change Data Capture supports more standard objects than PushTopic
events and provides more features such as header fields that contain information about the change
Platform Event
Publish and receive custom payloads with a predefined schema The data can be anything you define including business data such
as order information Specify the data to send by defining a platform event Subscribe to a platform event channel to receive
notifications
Legacy Events PushTopic and Generic Event
PushTopic and generic events are firstgeneration events They have limited support and are no longer updated with new features
We recommend that you use Change Data Capture events instead of PushTopic events and Platform Events instead of Generic
events

See the PubSub API documentation

SEE ALSO

Work With APIs

Give Integration Users API Only Access

Following the principle of least privilege we recommend creating and configuring one Salesforce
user for every integration Assigning a different user to each calling system use case domain or

API resource restricts those users to a unique subset of data Creating dedicated integration users

gives you more control over operations and traceability of transactions and minimizes the impact
if a user or integration is compromised

EDITIONS

Available in Enterprise
Unlimited Performance
and Developer Editions

The Salesforce Integration user license supports this best practice by offering a set of permissions

restricted to API access ideal for systemtosystem integration users This license makes the Salesforce

API Only System Integrations profile and the Salesforce API Integration permission set license available The Salesforce API Only System

Integrations profile ensures that the API is enabled and that the associated user is limited to interacting with Salesforce exclusively

through the API The Salesforce API Integration permission set license makes available many of the same user and object permissions

typically granted to Salesforce admins

Enhance Salesforce with Code

Download API WSDL and Client Certificates

Assign a dedicated integration user the Salesforce Integration user license and Salesforce API Only System Integrations profile to enable

and restrict access to the API Assign the Salesforce API Integration or other permission set licenses to make individual permissions

available Create permission sets to group a subset of the permissions made available via any assigned permission set licenses and assign
the permission set group to the integration user Follow the standard process in your Salesforce app to set up this user configuration

Combining the Salesforce Integration user license Salesforce API Only System Integrations profile Salesforce API Integration permission

set license and relevant permission sets grants the integration user access to the org and data while restricting that access exclusively

to API operations Its possible to assign various permission set licenses to a user with the Salesforce Integration user license However

the Salesforce API Integration permission set license is only available to users assigned the Salesforce Integration user license

Users assigned the Salesforce Integration user license and related permissions are not authorized to access Salesforce data or features

through any user interface The individual permissions granted through the Salesforce Integration license and the related Salesforce API

Only System Integrations profile cant be turned off including on any clones of the profile
By default orgs in supported editions are granted a limited number of Salesforce Integration user licenses Contact a Salesforce account
executive for information on how to purchase addon licenses
As a part of integration planning or after assigning permissions to an integration user learn how a user is authorized and authenticated

via the API so they can log in to an org For integrations using a RESTbased API create a connected app and use an OAuth flow For

integrations using a SOAPbased API use the SOAPspecific login call

SEE ALSO

Salesforce Developer Integration Patterns and Practices
Licenses Overview
Standard Profiles

Which API Do I Use

REST API Developer Guide Authorization Through Connected Apps and OAuth

SOAP API Developer Guide login

Download API WSDL and Client Certificates

To integrate your applications with Salesforce using the API download a Web Services Description

Language WSDL document

EDITIONS

Enterprise WSDL Use this WSDL document to build an integration for a single org The

enterprise WSDL is strongly typed which means that it contains objects and fields with specific

data types such as int and string You must download and reconsume the enterprise

WSDL document when changes are made to the custom objects or fields in an org or when

you want to use a different version of the API

Available in both Salesforce
Classic and Lightning
Experience

Partner WSDL Use this WSDL to build an integration that works across multiple Salesforce

orgs regardless of their custom objects or fields Typically partners and ISVs use this WSDL Its

loosely typed which means that you work with namevalue pairs of field names and values

instead of specific data types The partner WSDL document needs to be downloaded and

consumed only once per version of the API

Apex WSDL Use this WSDL to run or compile Apex in another environment

Metadata WSDL Use this WSDL to migrate configuration changes between orgs or work with

the customizations in your org as XML metadata files

To download a WSDL document

From Setup enter API in the Quick Find box then select API

Available in Professional
Enterprise Developer and
Databasecom Editions

USER PERMISSIONS

To download a WSDL

Customize Application

Enhance Salesforce with Code

Manage API Usage Notifications

Download the appropriate WSDL

If youre downloading an enterprise WSDL and you have managed packages installed in your org click Generate Enterprise

WSDL Select the version of each installed package to include in the generated WSDL By default it is set to the latest installed

versions of the packages

Otherwise rightclick the link for the appropriate WSDL document to save it to a local directory In the menu Internet Explorer

users can choose Save Target As while Google Chrome and Mozilla Firefox users can choose Save Link As

On your computer import the local copy of the WSDL document into your development environment

Note You can also select the default package versions without downloading a WSDL in the Package Version Settings section

Optionally you can download a certificate to authenticate Salesforce orgs Use this certificate for workflow outbound messaging This
certificate identifies that the request comes from Salesforce not a specific user If you want to use certificates to ensure secure connections
using other Salesforce features such as Apex callouts use Salesforce certificates and key pairs
To download a certificate

From Setup enter API in the Quick Find box then select API

In Client Certificate section click Manage API Client Certificate

In the API Client Certificate section click the API Client Certificate

Click Download Certificate The crt file is saved in the download location specified in your browser
You can then import the downloaded certificate into your application server and configure your application server to request the
client certificate

SEE ALSO

Certificates and Keys
Work With APIs
Apex Developer Guide

Metadata API Developer Guide

Manage API Usage Notifications

When you create a request usage notification you specify an administrator to receive an email

notification whenever your organization exceeds a specified limit for the number of API requests

made in a specified span of hours

The API usage notifications list includes details such as who is getting notified how often and at

what thresholds You can create up to ten notifications per organization

EDITIONS

Available in both Salesforce
Classic and Lightning
Experience

Create an API Usage Notification

On the API Usage Notifications page you can supply the required values for a ratelimiting

notification

Available in Enterprise
Performance Unlimited
Developer and
Databasecom Editions

View API Usage Notifications

You can view edit delete or clone information about a API usage notification

USER PERMISSIONS

To view create edit or
delete notifications
Modify All Data

SEE ALSO

Work With APIs

Enhance Salesforce with Code

Manage API Usage Notifications

Create an API Usage Notification

On the API Usage Notifications page you can supply the required values for a ratelimiting

notification

EDITIONS

To create an API usage notification

Available in both Salesforce
Classic and Lightning
Experience

From Setup enter API Usage Notifications in the Quick Find box then select

API Usage Notifications

Click New
Enter the details
Notification Recipient The Salesforce user who will receive the notifications
Threshold The percentage of the rate limit that once exceeded in the specified notification
interval triggers a notification to be sent to the specified user Value must be between
and
Notification Interval Hours The time period for which the number of requests is measured
in hours For example if the interval is the rate must be exceeded in the past hours
for a notification to be sent

Available in Enterprise
Performance Unlimited
Developer and
Databasecom Editions

USER PERMISSIONS

To view create edit or
delete notifications
Modify All Data

If you change the time period the new time period does not take effect until after the next
notification of the existing time period For example assume you have set the time period to send notifications every hour Then

at pm you set the time period to send notifications every hours A last notification from the old time period is sent at

pm The next notification would be sent at pm the next day

SEE ALSO

View API Usage Notifications

Manage API Usage Notifications

View API Usage Notifications

You can view edit delete or clone information about a API usage notification

EDITIONS

Notification Recipient The username for the person to whom the email notification is sent
Threshold The percent of the usage limit that when reached triggers an email notification
Notification Interval Hours The frequency at which the notifications are sent For example if
the notification interval is four hours a notification is sent only if the last notification was sent
at least four hours ago Due to the asynchronous nature of the notification process Salesforce
cant guarantee the notification interval
Created By The user who created the notification request and the time it was created
Modified By The user who last edited the notification
You can also create a new notification based on the values of the notification being displayed Click
Clone to create a new notification with the current values populated in the new notification You
can edit the values before saving

SEE ALSO

Create an API Usage Notification

Manage API Usage Notifications

Available in both Salesforce
Classic and Lightning
Experience
Available in Enterprise
Performance Unlimited
Developer and
Databasecom Editions

USER PERMISSIONS

To view create edit or
delete notifications
Modify All Data

Enhance Salesforce with Code

Write Code

Write 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
Work with Code
This section contains information about the tools and techniques you can use when making changes to your organization by using
code
Custom Metadata Types
You can create your own declarative developer frameworks for internal teams partners and customers Rather than building apps
from data you can build apps that are defined and driven by their own types of metadata Metadata is the information that describes
the configuration of each customers organization
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
Remote Access Application
Connected apps have replaced remote access apps Use connected apps for apps that require integration with Salesforce to verify
users and control security policies for external apps
Secure Identity for the Internet of Things

Asset tokens are an openstandardsbased JWT authentication token for verifying and securing requests from connected devices

They identify the device to a backend service that processes the stream of data and events from the device They allow registration

of device data with the Salesforce platform and linking it to Salesforce CRM data about the customer account or contact helping

you to act on behalf of the customer You can even support custom business processes using asset token events Asset tokens enable
more proactive support and more predictive engagement with your customers on an unprecedented scale

SEE ALSO

Work With APIs
Debug Your Code
Test Your Changes
Secure Your Code

Enhance Salesforce with Code

Salesforce Development Tools

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 Visual
Studio Code

Visual Studio Code
Marketplace

Salesforce CLI

developersalesforcecom

DevOps Center

Setup

Developer Console

Your Name or the

Available in Salesforce
Classic or Lightning
Experience depends on tool
The available tools vary
according to which
Salesforce Edition you have

quick access menu

Visualforce development mode
footer

Setup or your personal
settings

Code editor

Setup

Apex Test Execution

Setup

Change Sets

Setup

Ant Migration Tool

developersalesforcecom

SEE ALSO

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

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

Enhance Salesforce with Code

Developer Console

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 A

SOQL query retrieves data from a single object or multiple related objects in the database You can execute a SOQL query immediately

after data is added to the database A SOSL query is a freeform text search that retrieves multiple related or unrelated objects and

fields Using SOSL you can retrieve data for a specific term that exists within a field And SOSL can tokenize multiple terms to find

relevant records It can take several minutes for data to be indexed before you can execute a query and get results
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

Click Developer Console

***