Salesforce
This integration allows you to set up a process in Salesforce that automatically triggers sending a Thnks via an Apex callout.
Configuring Salesforce to Automatically Send a Thnks
This guide walks you through automatically triggering the sending of a Thnks using Salesforce Process Builder or Apex triggers.
Prerequisites
-
Access to the Thnks API.
-
Thnks API Key (Authorization Token).
-
URL for Thnks API endpoint.
-
Administrative access to Salesforce for creating custom fields and Apex classes.
Setup
Prepare Webhook Data
Before setting up the integration, ensure you have the following details:
Thnks API URL
https://api.thnks.com/api/v1/gift_requests
HTTP Method
POST
Data (JSON format)
Here’s an example of the JSON payload you will need to include in the request. You’ll need to replace the placeholders with the appropriate Salesforce tokens or field variables:
-
Replace
<GIFT_ID>
with the Thnks ID of the gift you want to send. -
Use Salesforce merge fields or dynamic data variables (e.g.,
{!Contact.Email}
) to populate lead or contact information.
Headers
You will need to add the following headers in the API call:
-
Content-Type:
application/json
-
Authorization: Your Thnks API key (Authorization Token).
Create an Apex Class for the API Callout
Navigate to Setup in Salesforce
Go to Setup and search for Apex Classes.
Create a New Apex Class
Write an Apex class for making the API callout to the Thnks endpoint. Below is an example Apex class:
Replace YOUR_API_KEY
with your actual Thnks API Key. Save the class.
Trigger the Apex Class
Use Process Builder or Flow
-
Create a Process in Process Builder or a Flow in Salesforce to trigger the Apex class.
-
Define the criteria for when the gift should be sent (e.g., Opportunity Stage Closed Won or Lead Status Changed).
-
Use the Apex Action to call the
ThnksGiftSender.sendGift
method, passing the required parameters (e.g., Gift ID, Contact Email, First Name, Last Name, and Message).
Use an Apex Trigger (Optional)
If you prefer to automate via triggers, you can create a trigger to call the ThnksGiftSender.sendGift
method based on object changes. Below is an example trigger for a Contact:
Replace GIFT_ID
with the appropriate Thnks gift ID.
Test and Verify
Run a Test with Sample Data
Test the Process Builder workflow, Flow, or Trigger using sample data to ensure the API callout works as expected.
Check Logs
Verify the API callout response in the Apex Logs to ensure the gift was sent successfully.
Make Adjustments if Necessary
Update your Apex class, parameters, or process settings based on test results.
Best Practices
Error Handling
Add error handling in your Apex class to manage failed API callouts.
Security
Store your API key securely using Custom Metadata Types or Named Credentials in Salesforce.
Testing
Test the integration thoroughly to ensure tokens, parameters, and triggers function as intended.
Following this process, you can automatically trigger a Thnks gift to be sent as part of a Salesforce workflow using an Apex callout.