Welcome to Developing with DocuSign.
This is Paige Rossi, a member of the developer content team.
And today, I'll be walking you through embedded signing
with the Apex Toolkit.
So what is the Apex Toolkit?
The Apex Toolkit enables Salesforce developers
to integrate DocuSign into Salesforce apps and processes.
It is similar to a Software Development Kit, or SDK.
And it exposes a full set of programmatic objects
and methods that you can call from your Apex code.
Before you start developing with the Apex Toolkit,
there are a few prerequisites.
First, you'll need a Salesforce org.
You need to make sure that my domain is enabled in that org.
You will also need a DocuSign account or a free DocuSign
developer account.
You need to integrate the DocuSign account associated
with your Salesforce org with the DocuSign eSignature
for Salesforce essentials managed package.
Finally, you will need to install Visual Studio code
with the Salesforce extension and the Salesforce command line
interface.
The Salesforce extension also requires that you have either
Java 8 or Java 11 installed.
Now let's get started.
I'm going to demonstrate how to use
the Apex Toolkit to initiate an embedded signing session.
Embedded signing allows your users
to sign documents without ever having to leave Salesforce.
Instead of receiving an email with a link to the document,
users can click a button inside Salesforce
that will direct them to a new signing URL
where they can sign the document.
Once signing is complete, the user
is redirected to Salesforce.
To create a button in Salesforce,
I first need to create a lightning web component.
Luckily, Salesforce makes it easy to develop lightning web
components within Salesforce Developer Experience, or SFDX,
projects in Visual Studio code.
To create a new project, press Command Shift
P on a Mac or Control Shift P on Windows.
Then type SFDX and select SFDX Create Project.
This creates a new Salesforce project
with the framework you need to create classes and lightning
web components.
Now that I have my new SFDX project,
I can create a new class.
I'll right click Classes in the left-hand menu
and select SFDX Create Apex Class.
This is where I'll write the code that
will use the Apex Toolkit and initiate embedded signing.
Within my new class, I'll create two methods.
The first method, send envelope, creates an empty envelope
and adds a document from a DocuSign template to it.
Later, I'll show you how to get the template ID that
will be passed to the method as a parameter.
In the same class, I'll create a second method
that will return an embedded signing URL.
This method takes an envelope as a parameter.
And when it is called, it will direct the user
to the returned URL where they can sign the document contained
in that envelope.
Now that I have created the class that
will initiate embedded signing, it's
time to create a lightning web component.
Lightning web components are custom elements
that you can add to your Salesforce pages.
They are developed with HTML and JavaScript.
To create a new lightning web component,
I will navigate to the forceapp/main/default/lwc
folder in the menu on the left.
I'll right click LWC and select SFDX Create Lightning Web
Component.
This will generate the three files that I need.
First, I'll edit my HTML in the dot HTML
file creating a Start Embedded Signing Session button.
Next, I need to make sure that my component has
the right metadata.
I will open the dot JS meta dot XML file, making sure
that is exposed is set to true and that there are targets
for the necessary pages.
Then I'll write some JavaScript, so that the user's interaction
with the component executes the methods I defined earlier.
Now than I am calling my methods,
I need to get a DocuSign template
ID to pass as a parameter.
To get a template ID, navigate to Templates in your DocuSign
account, open the template you want to use,
and select Template ID.
Now that I have written all of this code in Visual Studio
code, it's time to deploy it to my Salesforce org.
To do that, I'll navigate to forceapp/main/default
in the left menu, right click, and select
SFDX Deploy Source To Org.
Once my code is deployed, I can access my new component
in Salesforce.
I'm going to add it to the sales console app.
To edit the page, click the gear icon
in the upper right-hand corner and select Edit Page.
In the lightning app builder, I'll
scroll to the custom components on the left
to find my new component.
I will drag it on the page and click Save.
Now there is an embedded signing button on my sales console.
When I click the button, I'm directed
to the embedded signing session.
When signing is complete, I am directed back
to the sales console.
My new embedded signing button allows
me to sign a document with DocuSign
without needing to leave Salesforce.
Now that you know how to use the Apex
Toolkit for embedded signing, you're
ready to build out your DocuSign and Salesforce
integration with Apex.
DocuSign University has a course on the Apex Toolkit.
And you can find guides and code examples on the DocuSign
developer center.
There are also a variety of trailheads
that can help you get started developing with Apex.
The DocuSign developer center has many more resources
to help you learn how to develop with DocuSign.
Don't forget to subscribe to our YouTube channel
for more developing with DocuSign videos.
Thanks for joining us.