-
Notifications
You must be signed in to change notification settings - Fork 579
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1492 from alexed1/ColProc_ConvertStringToCol
Col proc convert string to col
- Loading branch information
Showing
16 changed files
with
353 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
flow_action_components/ConvertCSVandStringCollection/packaging/CreateNewUnlockedPackage.bat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
@echo off | ||
if "%1" neq "" set packageName=%1 | ||
@echo on | ||
sfdx package:create -v lexhost --name "%packageName%" --path force-app --package-type Unlocked |
4 changes: 4 additions & 0 deletions
4
flow_action_components/ConvertCSVandStringCollection/packaging/CreateNewVersion.bat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
@echo off | ||
if "%1" neq "" set version=%1 | ||
@echo on | ||
sfdx package:version:create -v lexhost -w 20 -x -c -n %version%.0 -d force-app\ |
5 changes: 5 additions & 0 deletions
5
flow_action_components/ConvertCSVandStringCollection/packaging/Details.bat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@echo off | ||
if "%1" neq "" set packageName=%1 | ||
if "%2" neq "" set version=%2 | ||
@echo on | ||
sfdx package:version:report -v lexhost --package "%packageName%@%version%" |
5 changes: 5 additions & 0 deletions
5
flow_action_components/ConvertCSVandStringCollection/packaging/Promote.bat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@echo off | ||
if "%1" neq "" set packageName=%1 | ||
if "%2" neq "" set version=%2 | ||
@echo on | ||
sfdx package:version:promote -v lexhost --package "%packageName%@%version%" |
9 changes: 9 additions & 0 deletions
9
flow_action_components/ConvertCSVandStringCollection/packaging/SetPackageName.bat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
@echo off | ||
if "%1" neq "" goto skipprompt | ||
set /p packageName="Set Package Name: " | ||
goto exit | ||
:skipprompt | ||
set packageName=%1 | ||
:exit | ||
echo Package Name: %packageName% | ||
@echo on |
9 changes: 9 additions & 0 deletions
9
flow_action_components/ConvertCSVandStringCollection/packaging/SetVersion.bat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
@echo off | ||
if "%1" neq "" goto skipprompt | ||
set /p version="Set Version Number: " | ||
goto exit | ||
:skipprompt | ||
set version=%1 | ||
:exit | ||
echo Version: %version% | ||
@echo on |
4 changes: 4 additions & 0 deletions
4
flow_action_components/ConvertCSVandStringCollection/packaging/ShowVersion.bat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
@echo off | ||
echo Package Name: %packageName% | ||
echo Version: %version% | ||
@echo on |
100 changes: 100 additions & 0 deletions
100
...lectionProcessors/force-app/main/default/classes/ConvertCSVStringCollectionController.cls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/** | ||
* Call an Invocable Action from a Reactive Flow Screen Component | ||
* | ||
* Sample Controller with an AuraEnabled class, that calls an Invocable Flow Action, designed to be called by an LWC that is | ||
* exposed to flow as a reactive Flow Screen Component | ||
* | ||
* Created By: Eric Smith | ||
* | ||
* 12/12/23 Version: 1.0.2 Initial Release | ||
* | ||
* LWC: convertCSVStringCollection_rsc | ||
* Controller: ConvertCSVStringCollectionController, ConvertCSVStringCollectionControllerTest | ||
* Actions: ConvertCSVToStringCollection, ConvertStringCollectionToCSV | ||
* Original: Convert Strings to String Collections, and Vice Versa (https://unofficialsf.com/new-flow-actions-to-convert-csv-strings-to-string-collections-and-vice-versa/) | ||
* Requires v1.3 or later | ||
**/ | ||
|
||
// Code commented this way is a standard part of the template and should stay as is | ||
// * Code commented this way should be adjusted to fit your use case | ||
|
||
// * Give the class a name similar to the invocable action | ||
public with sharing class ConvertCSVStringCollectionController { | ||
|
||
// * Define each of the attributes to be returned by the invocable action and then passed back to the calling LWC | ||
public class ReturnResultsWrapper { | ||
List<String> stringCollectionOut; // String to Collection | ||
String csvStringOut; // Collection to String | ||
} | ||
|
||
@AuraEnabled | ||
// * Give the method a name similar to the invocable action | ||
public static String convertCSVCollection( | ||
// * Define each of the arguments to be passed into this controller by the LWC and then directly on to the invocable action | ||
String csvStringIn, // String to Collection | ||
List<String> stringCollectionIn, // Collection to String | ||
String delimiter // Used for both | ||
) { | ||
|
||
// Initialize the return results object | ||
ReturnResultsWrapper curRR = new ReturnResultsWrapper(); | ||
|
||
// * Set the 2nd argument to the name of the Invocable Apex Action | ||
// String to Collection | ||
Invocable.Action action1 = Invocable.Action.createCustomAction('apex', 'ConvertCSVToStringCollection'); | ||
// Collection to String | ||
Invocable.Action action2 = Invocable.Action.createCustomAction('apex', 'ConvertStringCollectionToCSV'); | ||
|
||
// * For each of the action's input attributes (Request), set the 1st argument to the name of the InvocableVariable | ||
// * and the 2nd argument to the corresponding value passed into this controller | ||
// String to Collection | ||
action1.setInvocationParameter('delimiter', delimiter); | ||
action1.setInvocationParameter('csvString', csvStringIn); | ||
// Collection to String | ||
action2.setInvocationParameter('delimiter', delimiter); | ||
action2.setInvocationParameter('stringCollection', stringCollectionIn); | ||
|
||
// Invoke the action | ||
List<Invocable.Action.Result> results1 = action1.invoke(); // String to Collection | ||
List<Invocable.Action.Result> results2 = action2.invoke(); // Collection to String | ||
|
||
// * Clear prior results | ||
curRR.stringCollectionOut = New List<String>(); | ||
curRR.csvStringOut = ''; | ||
|
||
// If a result was returned ... | ||
if (results1.size() > 0 && results1[0].isSuccess()) { // String to Collection | ||
// * Assign each of the returned attributes to the corresponding value in the ReturnResultsWrapper | ||
curRR.stringCollectionOut = objToList(results1[0].getOutputParameters().get('stringCollection')); | ||
} | ||
if (results2.size() > 0 && results2[0].isSuccess()) { // Collection to String | ||
// * Assign each of the returned attributes to the corresponding value in the ReturnResultsWrapper | ||
curRR.csvStringOut = objToString(results2[0].getOutputParameters().get('csvString')); | ||
} | ||
|
||
// Return the results wrapper to the calling LWC | ||
return JSON.serialize(curRR); | ||
|
||
} | ||
|
||
// Convert an object to a list of objects and fix date format | ||
// private static List<SObject> objToObj(Object obj) { | ||
// return (List<SObject>) JSON.deserialize(JSON.serialize(obj).replace('+0000','Z'), List<SObject>.class); | ||
// } | ||
|
||
// Convert an object to a list of strings | ||
private static List<String> objToList(Object obj) { | ||
return (List<String>) JSON.deserialize(JSON.serialize(obj), List<String>.class); | ||
} | ||
|
||
// Convert an object to a String | ||
private static String objToString(Object obj) { | ||
return String.valueof(obj); | ||
} | ||
|
||
// Convert an object to an integer | ||
// private static Integer objToInteger(Object obj) { | ||
// return Integer.valueof(obj); | ||
// } | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
...ocessors/force-app/main/default/classes/ConvertCSVStringCollectionController.cls-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>59.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |
22 changes: 22 additions & 0 deletions
22
...ionProcessors/force-app/main/default/classes/ConvertCSVStringCollectionControllerTest.cls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
@isTest | ||
public with sharing class ConvertCSVStringCollectionControllerTest { | ||
|
||
@isTest | ||
static void testConvert() { | ||
|
||
List<String> textCollection = new List<String>{}; | ||
String csvString = 'abc;def'; | ||
|
||
String result = ConvertCSVStringCollectionController.convertCSVCollection(csvString, textCollection, ';'); | ||
Map<String, Object> resultMap = (Map<String, Object>) JSON.deserializeUntyped(result); | ||
List<String> objAsStrings = (List<String>) JSON.deserialize(JSON.serialize( resultMap.get('stringCollectionOut') ), List<String>.class); | ||
Assert.areEqual( objAsStrings[0], 'abc' ); | ||
Assert.areEqual( objAsStrings[1], 'def' ); | ||
|
||
result = ConvertCSVStringCollectionController.convertCSVCollection('', objAsStrings, ';'); | ||
resultMap = (Map<String, Object>) JSON.deserializeUntyped(result); | ||
Assert.areEqual( csvString, resultMap.get('csvStringOut') ); | ||
|
||
} | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
...sors/force-app/main/default/classes/ConvertCSVStringCollectionControllerTest.cls-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>58.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |
12 changes: 12 additions & 0 deletions
12
...e-app/main/default/lwc/convertCSVStringCollection_rsc/convertCSVStringCollection_rsc.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<template> | ||
|
||
<!-- This template includes a standard 'error' output attribute that will be exposed on the flow screen --> | ||
<template if:true={error}> | ||
<!-- * insert the name of the action in the error message--> | ||
The Convert CSV String Collection screen component on this screen is reporting the following Error: {error} | ||
</template> | ||
|
||
<!-- Track, but do not display the reactive attribute(s) --> | ||
<span hidden><lightning-formatted-text value={reactiveValue} onchange={handleOnChange}></lightning-formatted-text></span> | ||
|
||
</template> |
Oops, something went wrong.