Skip to content

Commit

Permalink
Merge pull request #1585 from alexed1/add-case-token
Browse files Browse the repository at this point in the history
added GetCaseThreadToken directory to flow action components
  • Loading branch information
alexed1 authored Oct 12, 2024
2 parents f140064 + fbdd31a commit 1deeed6
Show file tree
Hide file tree
Showing 15 changed files with 273 additions and 0 deletions.
15 changes: 15 additions & 0 deletions flow_action_components/GetCaseThreadToken/.forceignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# List files or directories below to ignore them when running force:source:push, force:source:pull, and force:source:status
# More information: https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_exclude_source.htm
#

package.xml

# LWC configuration files
**/jsconfig.json
**/.eslintrc.json

# LWC Jest
**/__tests__/**
**/tsconfig.json

**/*.ts
4 changes: 4 additions & 0 deletions flow_action_components/GetCaseThreadToken/.husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm run precommit
21 changes: 21 additions & 0 deletions flow_action_components/GetCaseThreadToken/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 almc-c

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
20 changes: 20 additions & 0 deletions flow_action_components/GetCaseThreadToken/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Get Case Thread Token Flow Action
Salesforce Email To Case Lightning Threading Token - The new Lightning Threading Token cannot be derived in a formula like the legacy Ref Id (i.e. `ref:_00Dxx1gEW._500xxYktl:ref` or `ref:!00Dxx01gEW.!500xx0Yktl:ref
`). Rather each recordId has a unique threading token that cannot be derived in the same way.

This invocable apex action allows for passing the case id and returning the thread token. The class Implements the EmailMessages.getFormattedThreadingToken(caseId) method to return a formatted string such as `thread::pp5XPGfmNf2hRZdRCWnrohc::`

**Use Case:**\
Used when you must stamp the thread token into a screen flow, or onto the case record itself to consume directly, from list view, report, global search, etc for interactivity with your users.

**Post Install:**\
Simply add your own custom text field (255) to the case object, assign to layout, grant permissions, and connect it to an after-save record-triggered flow on case to assign the token field.

**Salesforce install links:**\
prod: https://login.salesforce.com/packaging/installPackage.apexp?p0=04taj00000039ht \
sandbox: https://test.salesforce.com/packaging/installPackage.apexp?p0=04taj00000039ht

**More info:**\
https://help.salesforce.com/s/articleView?id=sf.support_email_to_case_threading.htm&type=5

https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_System_EmailMessages_getFormattedThreadingToken.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"orgName": "almc0137 company",
"edition": "Developer",
"features": ["EnableSetPasswordInApi"],
"settings": {
"lightningExperienceSettings": {
"enableS1DesktopEnabled": true
},
"mobileSettings": {
"enableS1EncryptedStoragePref2": false
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"plugins": ["@salesforce/eslint-plugin-aura"],
"extends": ["plugin:@salesforce/eslint-plugin-aura/recommended"],
"rules": {
"vars-on-top": "off",
"no-unused-expressions": "off"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Created: 9/19/2024 AMM
* Scope: Given a caseId, get the thread token and return it to the caller, so that a flow can execute operations with thread token.
* Uses: Lightning Threading enabled in org, allows flow to retrieve the Thread Token provided in merge fields for email to case.
* Helper method to stamp Token on case or flow interface for user interactions.
* Refs: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_InvocableMethod.htm
*
* @param caseId (list)
* @return threadToken (list)
*/

global with sharing class GetCaseThreadToken {

@InvocableMethod(label = 'Get Case Thread Token' description = 'Provide a caseId and get back the thread token for the case that is provided to emails from case')
global static List <Outputs> getTokenFromCaseId (List<Inputs> requestList) {

//Wrap the Results object in a List container (an extra step added to allow this interface to also support bulkification)
List<Outputs> responseList = new List<Outputs>();

for (Inputs req : requestList) {
Outputs resp = new Outputs();
resp.threadToken = EmailMessages.getFormattedThreadingToken(req.caseId);
responseList.add(resp);
}

return responseList;
}

global class Inputs {
@InvocableVariable(required=true)
global Id caseId;
}

global class Outputs {
@InvocableVariable
global String threadToken;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>61.0</apiVersion>
<status>Active</status>
</ApexClass>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@IsTest
private class GetCaseThreadTokenTest {

@IsTest
static void getTokenFromCaseIdTest() {

// Set up a test request list
List<GetCaseThreadToken.Inputs> myRequestedCaseIds = new List<GetCaseThreadToken.Inputs>();

//make cases, test for bulkification
List<Case> casesToInsert = new List<Case>();
for(Integer i=0;i<201;i++){
casesToInsert.add( new case(subject='Case '+ i, Description='Case '+ i) );
}
Insert(casesToInsert);
system.debug(casesToInsert);

//now cast the Id's back in as requests.
for(Case c : casesToInsert){
GetCaseThreadToken.Inputs myReq = new GetCaseThreadToken.Inputs();
myReq.caseId = c.Id;
myRequestedCaseIds.add(myReq);
}

//then call the method; pass the list
List<GetCaseThreadToken.Outputs> myCaseThreadTokens = GetCaseThreadToken.getTokenFromCaseId(myRequestedCaseIds);

//examine the list
system.debug( 'myCaseThreadTokens.size()' );
system.debug( myCaseThreadTokens.size() );

//then run assertions to see if we got back the same number of Thread Tokens
Assert.areEqual(casesToInsert.size(), myCaseThreadTokens.size());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>61.0</apiVersion>
<status>Active</status>
</ApexClass>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": ["@salesforce/eslint-config-lwc/recommended"],
"overrides": [
{
"files": ["*.test.js"],
"rules": {
"@lwc/lwc/no-unexpected-wire-adapter-usages": "off"
},
"env": {
"node": true
}
}
]
}
6 changes: 6 additions & 0 deletions flow_action_components/GetCaseThreadToken/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const { jestConfig } = require('@salesforce/sfdx-lwc-jest/config');

module.exports = {
...jestConfig,
modulePathIgnorePatterns: ['<rootDir>/.localdevserver']
};
36 changes: 36 additions & 0 deletions flow_action_components/GetCaseThreadToken/manifest/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>*</members>
<name>ApexClass</name>
</types>
<types>
<members>*</members>
<name>ApexComponent</name>
</types>
<types>
<members>*</members>
<name>ApexPage</name>
</types>
<types>
<members>*</members>
<name>ApexTestSuite</name>
</types>
<types>
<members>*</members>
<name>ApexTrigger</name>
</types>
<types>
<members>*</members>
<name>AuraDefinitionBundle</name>
</types>
<types>
<members>*</members>
<name>LightningComponentBundle</name>
</types>
<types>
<members>*</members>
<name>StaticResource</name>
</types>
<version>61.0</version>
</Package>
41 changes: 41 additions & 0 deletions flow_action_components/GetCaseThreadToken/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "salesforce-app",
"private": true,
"version": "1.0.0",
"description": "Salesforce App",
"scripts": {
"lint": "eslint **/{aura,lwc}/**/*.js",
"test": "npm run test:unit",
"test:unit": "sfdx-lwc-jest",
"test:unit:watch": "sfdx-lwc-jest --watch",
"test:unit:debug": "sfdx-lwc-jest --debug",
"test:unit:coverage": "sfdx-lwc-jest --coverage",
"prettier": "prettier --write \"**/*.{cls,cmp,component,css,html,js,json,md,page,trigger,xml,yaml,yml}\"",
"prettier:verify": "prettier --check \"**/*.{cls,cmp,component,css,html,js,json,md,page,trigger,xml,yaml,yml}\"",
"postinstall": "husky install",
"precommit": "lint-staged"
},
"devDependencies": {
"@lwc/eslint-plugin-lwc": "^1.1.2",
"@prettier/plugin-xml": "^3.2.2",
"@salesforce/eslint-config-lwc": "^3.2.3",
"@salesforce/eslint-plugin-aura": "^2.0.0",
"@salesforce/eslint-plugin-lightning": "^1.0.0",
"@salesforce/sfdx-lwc-jest": "^3.1.0",
"eslint": "^8.11.0",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-jest": "^27.6.0",
"husky": "^8.0.3",
"lint-staged": "^15.1.0",
"prettier": "^3.1.0",
"prettier-plugin-apex": "^2.0.1"
},
"lint-staged": {
"**/*.{cls,cmp,component,css,html,js,json,md,page,trigger,xml,yaml,yml}": [
"prettier --write"
],
"**/{aura,lwc}/**/*.js": [
"eslint"
]
}
}
12 changes: 12 additions & 0 deletions flow_action_components/GetCaseThreadToken/sfdx-project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"packageDirectories": [
{
"path": "force-app",
"default": true
}
],
"name": "getThreadTokenFlowAction",
"namespace": "",
"sfdcLoginUrl": "https://login.salesforce.com",
"sourceApiVersion": "61.0"
}

0 comments on commit 1deeed6

Please sign in to comment.