Our Case Triggers script enables you to map access to SendSafely packages on a Salesforce Case to changes in the status or assignment of that Case. The Case Triggers script is an AWS Lambda function deployed via CloudFormation template. In this article, we’ll walk you through how to deploy and configure it to tighten up who in your Salesforce environment has access to sensitive customer data.
Overview
When the status or assignment of a Salesforce Case changes, this script performs specified actions on all SendSafely packages in that Case’s Chatter Feed.
| Action | Description |
| revoke_access_to_packages | Removes all recipients, except the package owners, from all packages on the Case. |
| add_user_to_packages | Adds a specified user to all packages on the Case. |
| remove_user_from_packages | Removes a specified user from all packages on the Case. |
| add_contact_group_to_packages | Adds a Contact Group to all packages on the Case. |
| delete_packages | Permanently deletes all packages on the Case. |
Prerequisites
- An AWS account with permission to deploy the CloudFormation and the resources it generates (a Lambda function, Secrets Manager entry, IAM role, CloudWatch logs, SNSTopic for error reporting, etc.)
- A Salesforce System Admin account
- A SendSafely Admin account with API access
Part 1: AWS Configuration
Step 1: Deploy the CloudFormation Template
- Deploy the CloudFormation template provided by your account rep.
- After deployment, note the Output URL from the CloudFormation stack. You'll use this as the webhook to invoke the Lambda from Salesforce.
Step 2: Configure Secrets Manager Entries
Store the following credentials in AWS Secrets Manager:
| Secret Key | Description |
| sendsafely_api_key | Your SendSafely Admin API Key |
| sendsafely_api_secret | Your SendSafely Admin API Secret |
| sendsafely_base_url | The URL of your SendSafely portal, e.g., https://yourcompany.sendsafely.com |
| salesforce_consumer_key | Your Salesforce Connected App Consumer Key |
| salesforce_consumer_secret | Your Salesforce Connected App Consumer Secret |
| salesforce_refresh_token | Your Salesforce Refresh Token (you can use our getRefreshToken.js utility script to get one) |
| salesforce_is_sandbox | Set to true for Sandbox, false for Production |
Part 2: Salesforce Configuration
Navigate to Salesforce Setup.
Step 1: Create External Credentials
- In Setup, search for and select Named Credentials.
- Click the External Credentials tab.
- Click New.
- Enter a Label and Name of your choice.
- For Authentication Protocol, select No Authentication.
- Click Save.
- Scroll down to the Principals section and click New.
- Enter Named Principal as the Parameter Name.
- Click Save.
Step 2: Create Named Credentials
- Click the Named Credentials tab.
- Click New.
- Enter a label of your choice.
- Paste the CloudFormation output URL into the URL field.
- Select Enabled for Callouts.
- For External Credential, select the credential you created in Step 1.
- Leave Client Certificate blank.
- Uncheck Generate Authorization Header.
- Click Save.
Step 3: Create Custom Metadata Type for Security
This stores a shared key used to verify requests are coming from your Salesforce org.
Create the Metadata Type
- In Setup, search for Custom Metadata Types and select it.
- Click New Custom Metadata Type.
- Fill in the following:
- Label: SendSafely Secret
- Plural Label: SendSafely Secrets
- Object Name: SendSafely_Secret
- Description: Shared Secret used for SendSafely-Salesforce case triggers
- Set visibility based on your org standards.
- Click Save.
Add a Custom Field
- On the Custom Metadata Type page, select SendSafely Secret.
- In the Custom Fields section, click New.
- Select Text as the data type and click Next.
- Configure the field:
- Field Label: HMAC Secret Key
- Length: 255
- Field Name: HmacSecretKey
- Check Required.
- Click Next, then Next, then Save.
Create the Metadata Record
- Return to Custom Metadata Types and click Manage Records next to SendSafely Secrets.
- Click New.
- Fill in:
- Label: Default
- SendSafely Secrets Name: Default
- HMAC Secret Key: Generate a 32-character random string (see commands below)
- Check Protected Component.
- Click Save.
Generate a random key:
On macOS/Linux:
openssl rand -base64 128On Windows PowerShell:
$bytes = New-Object byte[] 128
[Security.Cryptography.RandomNumberGenerator]::Create().GetBytes($bytes)
[Convert]::ToBase64String($bytes)Step 4: Create Apex Classes
Open the Salesforce Developer Console (click the gear icon, then Developer Console).
Create the Utility Class
- Go to File > New > Apex Class.
- Name it appropriately (e.g., CaseLambdaInvoker).
- Paste the contents of CaseLambdaInvoker.java from the SalesforceApexClasses directory.
- Update line 3: Replace Named_Credentials with your Named Credential name.
- Save the file.
Create the Trigger
- Go to File > New > Apex Trigger.
- Name it appropriately (e.g., CaseCloseLambdaTrigger).
- Paste the contents of CaseCloseLambdaTrigger.java from the SalesforceApexClasses directory.
- Save the file.
Create the Test Class
- Go to File > New > Apex Class.
- Name it appropriately (e.g., CaseLambdaInvokerTest).
- Paste the contents of CaseLambdaInvokerTest.java from the SalesforceApexClasses directory.
- Save the file.
Step 5: Configure Permission Sets
External Credential Access
- In Setup, search for Permission Sets.
- Click New.
- Enter a name and description.
- Click Save.
- Open the new Permission Set.
- Click External Credential Principal Access.
- Click Edit.
- Add your External Credential to the Enabled list.
- Click Save.
- Click Manage Assignments.
- Select your support agents and click Add Assignment.
Chatter API Access
- Create another Permission Set following steps 1-4 above.
- Click Object Settings.
- Select Cases.
- Click Edit.
- Enable Read, View All Records, and View All Fields.
- Click Save.
- Click Manage Assignments.
- Select the user whose credentials the Lambda will use.
- Click Add Assignment.
Request Body Examples
Single Action
Revoke access when case closes:
{
"case_id": "{{case.id}}",
"action": "revoke_access_to_packages"
}Add a user to packages:
{
"case_id": "{{case.id}}",
"action": "add_user_to_packages",
"email": "user@example.com"
}Add a contact group:
{
"case_id": "{{case.id}}",
"action": "add_contact_group_to_packages",
"contactGroupId": "your-contact-group-id"
}Delete all packages:
{
"case_id": "{{case.id}}",
"action": "delete_packages"
}Multiple Actions
You can execute multiple actions in sequence:
{
"case_id": "{{case.id}}",
"action": ["add_contact_group_to_packages", "add_user_to_packages"],
"contactGroupId": "your-contact-group-id",
"email": "user@example.com"
}Actions execute in the order specified in the array.
To Get Started
If you have questions about this integration, contact your SendSafely account rep.
Comments
0 comments
Please sign in to leave a comment.