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 January

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
Salesforce Development Tools
Replacement Tools for Workbench
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
Salesforce Development Tools
Salesforce provides various tools for all phases of app development
Replacement Tools for Workbench
Workbench httpsworkbenchdeveloperforcecom is an opensource tool for interacting with your org However because Salesforce
doesnt maintain Workbench we cant address issues or bugs related to using it We recommend that you use our alternative and

integrated tools instead such as Code Builder Salesforce CLI and VS Code Extensions

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

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

Replacement Tools for Workbench
Workbench httpsworkbenchdeveloperforcecom is an opensource tool for interacting with your org However because Salesforce
doesnt maintain Workbench we cant address issues or bugs related to using it We recommend that you use our alternative and

integrated tools instead such as Code Builder Salesforce CLI and VS Code Extensions

Table Tools for Interacting with Data and APIs
Workbench Feature

Available using Salesforce Available using VS Code Available using Postman

CLI

Code Builder

Data Insert Update Upsert
Delete Undelete or Purge

Yes see documentation

Yes using a Salesforce CLI

command in the terminal

Yes see documentation

Info Metadata Types
Components

No

Partial support see
documentation

Yes see documentation

Enhance Salesforce with Code

Replacement Tools for Workbench

Workbench Feature

Available using Salesforce Available using VS Code Available using Postman

CLI

Code Builder

Info Standard Custom
Objects

Yes see documentation

Yes using a Salesforce CLI

command in the terminal

Yes see documentation

Migration Deploy

Yes see documentation

Yes see documentation

No

Migration Retrieve

Yes see documentation

Yes see documentation

No

Utilities Bulk API Job Status

Yes see documentation for Bulk Yes using a Salesforce CLI

API v and Bulk API v

command in the terminal

Yes see documentation for Bulk

API v and Bulk API v

Utilities Metadata API Process Yes see documentation

Status

Yes using a Salesforce CLI

command in the terminal

No

Utilities REST Explorer

No

Yes see documentation

No

More Details

For Bulk API Salesforce CLI supports bulk ingest with Bulk API v and v Salesforce CLI doesnt currently support bulk queries

For REST API try using Mulesoft

Table Tools for Querying Using SOQL and SOSL

Workbench Feature

Available using Salesforce Available using VS Code Available using Postman

CLI

Code Builder

Queries Async Query

No

No

No

Queries SOQL Query

Yes see documentation

Yes see documentation

Yes see documentation

Queries SOSL Search

No

No

Yes see documentation

Queries Streaming Push
Topics

No

No

No

More Details

Async SOQL was retired in Summer

Push Topics is a deprecated feature Use Change Data Capture instead
Table Tools for Testing Apex Code
Workbench Feature

Available using Salesforce Available using VS Code Available using Postman

CLI

Code Builder

Utilities Apex Execute

Yes see documentation

Yes see documentation

SEE ALSO

Code Builder

Salesforce Extensions for VS Code

Salesforce CLI Command Reference

No

Enhance Salesforce with Code

Work With APIs

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

Give Integration Users API Only Access

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

assigning a different user to each calling system domain use case or API resource you restrict each of those users to a unique subset

of data and functionality Setting up dedicated integration users gives you more control over operations and traceability of transactions
And it minimizes the impact if a user or integration is compromised The Salesforce Integration user license supports this best practice
by offering a profile that restricts assigned users to APIonly access ideal for systemtosystem integration users

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

Enhance Salesforce with Code

Which API Do I Use

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

EDITIONS

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

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

USER PERMISSIONS

Analytics REST API

REST

JSON XML

Synchronous

User Interface API

REST

JSON

Synchronous

To use the APIs

API Enabled

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

Available in Professional

with API access enabled

Enterprise Performance
Unlimited and Developer
Editions

To use Apex classes and

methods as REST web

services

Enables access to Apex REST

services even if API Enabled

permission is not granted

Apex REST Services

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

Enhance Salesforce with Code

Which API Do I Use

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

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

Enhance Salesforce with Code

Which API Do I Use

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 Its best if jobs with fewer than records 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

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

Enhance Salesforce with Code

Give Integration Users API Only Access

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 By assigning a different user to each calling system domain use case or

API resource you restrict each of those users to a unique subset of data and functionality Setting

up dedicated integration users gives you more control over operations and traceability of transactions
And it minimizes the impact if a user or integration is compromised The Salesforce Integration user
license supports this best practice by offering a profile that restricts assigned users to APIonly
access ideal for systemtosystem integration users

EDITIONS

Available in Enterprise
Unlimited Performance
and Developer Editions

The Salesforce Integration user license makes the Minimum Access API Only Integrations profile and the Salesforce API Integration

permission set license available for assignment

Note The Minimum Access API Only Integrations profile replaces the deprecated Salesforce API Only System Integrations profile

which isnt available in newly provisioned orgs

The Minimum Access API Only Integrations profile enables and also restricts assigned users to operate via API You cant turn off the

APIonly access granted through this profile but you can change other capabilities permissions settings and data access granted to
users via this profile Find and review the profile in your org to understand what it can and cant control If your integration users need
more access than the profile provides use permission set licenses to expand the options

The Salesforce API Integration permission set license extends the functionality of the Salesforce Integration user license with many of

the same user and object permissions typically available on the System Administrator standard profile Find and review the Salesforce

API Integration permission set license on the Company Information page in Setup to see what it makes available Assign this or other

permission set licenses to users with the Minimum Access API Only Integrations profile to make more permissions available Configure

and assign permission sets or permission set groups to grant permissions to integration users so they can perform the API operations

Follow the standard process to find and assign the user license and profile and any permission set licenses permission sets and permission
set groups to your integration user

Considerations

Users assigned the Salesforce Integration user license and Salesforce API Only System Integrations profile 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 Minimum Access API Only 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

Enhance Salesforce with Code

Download API WSDL and Client Certificates

As a part of integration planning or after assigning permissions to an integration user decide how users are 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 including the Bulk 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

Available in Professional
Enterprise Developer and
Databasecom Editions

USER PERMISSIONS

To download a WSDL

Customize Application

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 navigate to Setup enter API in the Quick Find box then select API

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 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 To download a certificate navigate to Setup enter API

in the Quick Find box then select API

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

In Client Certificate section click Manage API Client Certificate

In the API Client Certificate section click the API Client Certificate

Enhance Salesforce with Code

Manage API Usage Notifications

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

Create an API Usage Notification

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

notification

EDITIONS

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

API Usage Notifications

Available in both Salesforce
Classic and Lightning
Experience

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

Enhance Salesforce with Code

Write Code

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

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

Create an API Usage Notification

Manage API Usage Notifications

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
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

***