From fbdd31a3025ca499468eefda2cd4f2551c9dd21e Mon Sep 17 00:00:00 2001 From: almc <70982080+almc-c@users.noreply.github.com> Date: Sat, 21 Sep 2024 09:27:28 -0500 Subject: [PATCH] added GetCaseThreadToken directory to flow action components --- .../GetCaseThreadToken/.forceignore | 15 +++++++ .../GetCaseThreadToken/.husky/pre-commit | 4 ++ .../GetCaseThreadToken/LICENSE | 21 ++++++++++ .../GetCaseThreadToken/README.md | 20 +++++++++ .../config/project-scratch-def.json | 13 ++++++ .../main/default/aura/.eslintrc.json | 8 ++++ .../default/classes/GetCaseThreadToken.cls | 38 +++++++++++++++++ .../classes/GetCaseThreadToken.cls-meta.xml | 5 +++ .../classes/GetCaseThreadTokenTest.cls | 35 ++++++++++++++++ .../GetCaseThreadTokenTest.cls-meta.xml | 5 +++ .../force-app/main/default/lwc/.eslintrc.json | 14 +++++++ .../GetCaseThreadToken/jest.config.js | 6 +++ .../GetCaseThreadToken/manifest/package.xml | 36 ++++++++++++++++ .../GetCaseThreadToken/package.json | 41 +++++++++++++++++++ .../GetCaseThreadToken/sfdx-project.json | 12 ++++++ 15 files changed, 273 insertions(+) create mode 100644 flow_action_components/GetCaseThreadToken/.forceignore create mode 100644 flow_action_components/GetCaseThreadToken/.husky/pre-commit create mode 100644 flow_action_components/GetCaseThreadToken/LICENSE create mode 100644 flow_action_components/GetCaseThreadToken/README.md create mode 100644 flow_action_components/GetCaseThreadToken/config/project-scratch-def.json create mode 100644 flow_action_components/GetCaseThreadToken/force-app/main/default/aura/.eslintrc.json create mode 100644 flow_action_components/GetCaseThreadToken/force-app/main/default/classes/GetCaseThreadToken.cls create mode 100644 flow_action_components/GetCaseThreadToken/force-app/main/default/classes/GetCaseThreadToken.cls-meta.xml create mode 100644 flow_action_components/GetCaseThreadToken/force-app/main/default/classes/GetCaseThreadTokenTest.cls create mode 100644 flow_action_components/GetCaseThreadToken/force-app/main/default/classes/GetCaseThreadTokenTest.cls-meta.xml create mode 100644 flow_action_components/GetCaseThreadToken/force-app/main/default/lwc/.eslintrc.json create mode 100644 flow_action_components/GetCaseThreadToken/jest.config.js create mode 100644 flow_action_components/GetCaseThreadToken/manifest/package.xml create mode 100644 flow_action_components/GetCaseThreadToken/package.json create mode 100644 flow_action_components/GetCaseThreadToken/sfdx-project.json diff --git a/flow_action_components/GetCaseThreadToken/.forceignore b/flow_action_components/GetCaseThreadToken/.forceignore new file mode 100644 index 000000000..3d36001b5 --- /dev/null +++ b/flow_action_components/GetCaseThreadToken/.forceignore @@ -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 diff --git a/flow_action_components/GetCaseThreadToken/.husky/pre-commit b/flow_action_components/GetCaseThreadToken/.husky/pre-commit new file mode 100644 index 000000000..feac116af --- /dev/null +++ b/flow_action_components/GetCaseThreadToken/.husky/pre-commit @@ -0,0 +1,4 @@ +#!/bin/sh +. "$(dirname "$0")/_/husky.sh" + +npm run precommit \ No newline at end of file diff --git a/flow_action_components/GetCaseThreadToken/LICENSE b/flow_action_components/GetCaseThreadToken/LICENSE new file mode 100644 index 000000000..81b1fd98c --- /dev/null +++ b/flow_action_components/GetCaseThreadToken/LICENSE @@ -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. diff --git a/flow_action_components/GetCaseThreadToken/README.md b/flow_action_components/GetCaseThreadToken/README.md new file mode 100644 index 000000000..9e194e88b --- /dev/null +++ b/flow_action_components/GetCaseThreadToken/README.md @@ -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 diff --git a/flow_action_components/GetCaseThreadToken/config/project-scratch-def.json b/flow_action_components/GetCaseThreadToken/config/project-scratch-def.json new file mode 100644 index 000000000..68d5032c3 --- /dev/null +++ b/flow_action_components/GetCaseThreadToken/config/project-scratch-def.json @@ -0,0 +1,13 @@ +{ + "orgName": "almc0137 company", + "edition": "Developer", + "features": ["EnableSetPasswordInApi"], + "settings": { + "lightningExperienceSettings": { + "enableS1DesktopEnabled": true + }, + "mobileSettings": { + "enableS1EncryptedStoragePref2": false + } + } +} diff --git a/flow_action_components/GetCaseThreadToken/force-app/main/default/aura/.eslintrc.json b/flow_action_components/GetCaseThreadToken/force-app/main/default/aura/.eslintrc.json new file mode 100644 index 000000000..226a5a27b --- /dev/null +++ b/flow_action_components/GetCaseThreadToken/force-app/main/default/aura/.eslintrc.json @@ -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" + } +} diff --git a/flow_action_components/GetCaseThreadToken/force-app/main/default/classes/GetCaseThreadToken.cls b/flow_action_components/GetCaseThreadToken/force-app/main/default/classes/GetCaseThreadToken.cls new file mode 100644 index 000000000..b323644cf --- /dev/null +++ b/flow_action_components/GetCaseThreadToken/force-app/main/default/classes/GetCaseThreadToken.cls @@ -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 getTokenFromCaseId (List requestList) { + + //Wrap the Results object in a List container (an extra step added to allow this interface to also support bulkification) + List responseList = new List(); + + 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; + } +} diff --git a/flow_action_components/GetCaseThreadToken/force-app/main/default/classes/GetCaseThreadToken.cls-meta.xml b/flow_action_components/GetCaseThreadToken/force-app/main/default/classes/GetCaseThreadToken.cls-meta.xml new file mode 100644 index 000000000..7d5f9e8a3 --- /dev/null +++ b/flow_action_components/GetCaseThreadToken/force-app/main/default/classes/GetCaseThreadToken.cls-meta.xml @@ -0,0 +1,5 @@ + + + 61.0 + Active + \ No newline at end of file diff --git a/flow_action_components/GetCaseThreadToken/force-app/main/default/classes/GetCaseThreadTokenTest.cls b/flow_action_components/GetCaseThreadToken/force-app/main/default/classes/GetCaseThreadTokenTest.cls new file mode 100644 index 000000000..ad1f5f88c --- /dev/null +++ b/flow_action_components/GetCaseThreadToken/force-app/main/default/classes/GetCaseThreadTokenTest.cls @@ -0,0 +1,35 @@ +@IsTest +private class GetCaseThreadTokenTest { + + @IsTest + static void getTokenFromCaseIdTest() { + + // Set up a test request list + List myRequestedCaseIds = new List(); + + //make cases, test for bulkification + List casesToInsert = new List(); + 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 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()); + } +} diff --git a/flow_action_components/GetCaseThreadToken/force-app/main/default/classes/GetCaseThreadTokenTest.cls-meta.xml b/flow_action_components/GetCaseThreadToken/force-app/main/default/classes/GetCaseThreadTokenTest.cls-meta.xml new file mode 100644 index 000000000..7d5f9e8a3 --- /dev/null +++ b/flow_action_components/GetCaseThreadToken/force-app/main/default/classes/GetCaseThreadTokenTest.cls-meta.xml @@ -0,0 +1,5 @@ + + + 61.0 + Active + \ No newline at end of file diff --git a/flow_action_components/GetCaseThreadToken/force-app/main/default/lwc/.eslintrc.json b/flow_action_components/GetCaseThreadToken/force-app/main/default/lwc/.eslintrc.json new file mode 100644 index 000000000..a82e76d70 --- /dev/null +++ b/flow_action_components/GetCaseThreadToken/force-app/main/default/lwc/.eslintrc.json @@ -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 + } + } + ] +} diff --git a/flow_action_components/GetCaseThreadToken/jest.config.js b/flow_action_components/GetCaseThreadToken/jest.config.js new file mode 100644 index 000000000..f5a9fed2b --- /dev/null +++ b/flow_action_components/GetCaseThreadToken/jest.config.js @@ -0,0 +1,6 @@ +const { jestConfig } = require('@salesforce/sfdx-lwc-jest/config'); + +module.exports = { + ...jestConfig, + modulePathIgnorePatterns: ['/.localdevserver'] +}; diff --git a/flow_action_components/GetCaseThreadToken/manifest/package.xml b/flow_action_components/GetCaseThreadToken/manifest/package.xml new file mode 100644 index 000000000..6f5516ae2 --- /dev/null +++ b/flow_action_components/GetCaseThreadToken/manifest/package.xml @@ -0,0 +1,36 @@ + + + + * + ApexClass + + + * + ApexComponent + + + * + ApexPage + + + * + ApexTestSuite + + + * + ApexTrigger + + + * + AuraDefinitionBundle + + + * + LightningComponentBundle + + + * + StaticResource + + 61.0 + \ No newline at end of file diff --git a/flow_action_components/GetCaseThreadToken/package.json b/flow_action_components/GetCaseThreadToken/package.json new file mode 100644 index 000000000..bba35bd70 --- /dev/null +++ b/flow_action_components/GetCaseThreadToken/package.json @@ -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" + ] + } +} diff --git a/flow_action_components/GetCaseThreadToken/sfdx-project.json b/flow_action_components/GetCaseThreadToken/sfdx-project.json new file mode 100644 index 000000000..ae509d4ae --- /dev/null +++ b/flow_action_components/GetCaseThreadToken/sfdx-project.json @@ -0,0 +1,12 @@ +{ + "packageDirectories": [ + { + "path": "force-app", + "default": true + } + ], + "name": "getThreadTokenFlowAction", + "namespace": "", + "sfdcLoginUrl": "https://login.salesforce.com", + "sourceApiVersion": "61.0" +}