Salesforce
Utilize External Services to automate direct mail
Last updated
Utilize External Services to automate direct mail
Last updated
Lob is pleased to offer an API integration within Salesforce, the world’s #1 CRM. Integrating Lob with Salesforce streamlines your direct mail campaigns by automating personalized outreach, enhancing customer engagement, and driving measurable results directly within your CRM.
With an integration via External Services, any Salesforce user can send automated direct mail, easily and at scale. External Services in Salesforce allow you to connect your Salesforce org to an external API. Using declarative tools and OpenAPI specifications to describe the external API functionality, External Services automatically creates invocable actions within Salesforce.
(Looking for a no-code integration option? See here.)
Download this JSON file (Lob OpenAPI specs) to use in Step 2.
First, create a new legacy credential for Lob.com in Salesforce.
Give it a label, a name, and set the URL field to https://api.lob.com/
Under Authentication, set the identity type to Named Principle, and set the authentication protocol to Password Authentication. In the username field, enter your test or live Lob API key. For the password field, copy and paste an empty character from a website like https://emptycharacter.com/.
Under Callout Options, there are no changes needed to the default selections.
Save the Named Credential.
Next, go to the External Services page and create a new External Service from API specification.
Fill in an External Service Name, an optional Description, then select "Complete JSON" for Service Schema, and select the Named Credential you just created.
In the JSON field, paste the entirety of the Lob OpenAPI specs you downloaded.
Click Save and Next. This will bring up a list of operations that you can do that were imported from those Lob OpenAPI specs.
In this step, we will set up the trigger and corresponding flow; in this example, when a lead is updated in SF, send a postcard from Lob.
Although this documentation uses a postcard flow as an example, you can still follow along for letter and self-mailer creation. (Swap in "letter" or "self-mailer" where you see "postcard" if using those form factors.)
Create a new Flow Trigger explorer and set it as an Actions and Related Records type.
Choose the object field and configure it for when the record is created or updated. (Ensure that Actions and Related Records is selected.)
Add a Scheduled Path called "zero hour delay" and set it to 0 hours after the record is created.
Next, create a new resource called "postcard_payload" with the data type as Apex defined and set it to postcard editable.
Use the Assignment node to map the required fields for creating a mail piece in Lob.
Map merge variables (optional)
If you plan to send creatives as HTML templates, you'll need to map out merge variables. One of the limitations of this integration within Salesforce is in how merge_variables are named. You'll notice that within the <mailpiece>_payload.merge_variables
field that there are parameters variable1
- variable10
listed. This is because there is no way to name merge variables dynamically within External Services for Salesforce.
So to work around it, any HTML templates used with Salesforce can only have merge variables named the same way, variable
1 - variable10
. The values of these can then be set accordingly within the Assignment action.
Back in the Flow, add an Action node to send a mailpiece creation request to Lob's API using the External Service you created earlier.
Map the "postcard_payload" resource to the "body" field in the Action.
Save and activate the flow. (You can debug it by selecting a test record and pressing the Debug button.)
Pro tip: Add a Fault Path for the action in case the SalesForce flow (not Lob API) fails at this step.
From the mail execution action, there was a resource created called Outputs from send_<mailpiece>
. There are three subfields; this data can be used within the flow to map information back into records.
200: the body of the successful request - this includes all data returned in the Lob API response, including "id," recipient information, "URL," "send_date" and so forth
default Exception: if the mailpiece was unsuccessful, including the error message and code
responseCode: the status code of the API request made to Lob, which is useful for making decision trees
Although you have successfully integrated and know where to retrieve output data, it's important to evaluate your responses. It's the difference between knowing whether your request to create a mailpiece was successful or not!
We can see this detail above in the image of a sample Salesforce flow, where we use the "Decision" action to evaluate if the mailpiece was sent.
You can edit the Decision:
Now, you have two forked paths:
success - your mailpiece request was successfully processed
Default Outcome - your mailpiece request failed (for example, because the address passed was undeliverable)
Now, you can add actions to the success path to act on the data you received back from the successful send (Outputs from send_postcard -> 200), or you can add actions to the Default Outcome path and perhaps notify an admin of the reason why the mailpiece request was denied (Outputs from send_postcard -> defaultExc -> error -> message )
Congratulations! You've successfully integrated Lob.com's API with Salesforce using External Services.
There are a number of computing resources that need to be monitored for SalesForce activities in order to ensure uninterrupted operations, Flows included!
These computing resources include:
CPU Time: There is a limit on how much CPU time can be consumed during a single transaction (e.g., 10 seconds). When your flow or other processes exceed this limit, you'll get a CPU time limit exceeded error.
SOQL Queries: Salesforce imposes a limit on the number of SOQL (Salesforce Object Query Language) queries that can be executed per transaction.
DML Operations: There's also a limit on the number of DML (Data Manipulation Language) operations like INSERT
, UPDATE
, DELETE
etc. that can be performed per transaction.
Heap Size: This is essentially the limit on the memory storage space used by variables, objects, etc., during a single transaction.
Callouts: These are HTTP requests to external services. There are limits on the number of callouts that can be made.
Elements: For flows specifically, there are limits on how many elements (like assignments, decisions, loops, etc.) you can have in a single flow.
If a flow exceeds a hard limit (like CPU time), it will be terminated immediately, and an error will be thrown. This can disrupt the business process that the flow was designed to manage. To manage these limitations, Salesforce administrators and developers have to keep a close eye on resource consumption and optimize flows and other customizations accordingly. Using tools like Salesforce Health Check can help you monitor your organization’s performance and stay within limits.
Need support? You can reach us at support@lob.com or submit a request.