-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add split string invocable class * add split string invocable test
- Loading branch information
1 parent
a791d17
commit 067e541
Showing
4 changed files
with
122 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
public with sharing class SplitStringInvocable { | ||
@InvocableMethod( | ||
label='Split String' | ||
description='Given a string and a delimiter, return a collection of strings' | ||
) | ||
public static List<List<String>> execute(List<Request> requests) { | ||
List<List<String>> output = new List<List<String>>(); | ||
for (Request req : requests) { | ||
output.add(req.inputText.split(req.delimiter)); | ||
} | ||
return output; | ||
} | ||
|
||
public class Request { | ||
@InvocableVariable(required=true label='Input Text') | ||
public String inputText; | ||
@InvocableVariable( | ||
required=true | ||
label='Separator' | ||
description='The delimiter that separates blocks of text inside your Input Text.' | ||
) | ||
public String delimiter = ';'; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
force-app/main/default/classes/SplitStringInvocable.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> |
88 changes: 88 additions & 0 deletions
88
force-app/main/default/classes/SplitStringInvocableTest.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,88 @@ | ||
@IsTest | ||
private class SplitStringInvocableTest { | ||
private static final String INPUT_TEXT_SEMICOLONS = 'monday;tuesday;wednesday;thursday;friday'; | ||
private static final String INPUT_TEXT_COMMAS = 'monday,tuesday,wednesday,thursday,friday'; | ||
private static final List<String> WEEK_DAYS; | ||
|
||
static { | ||
WEEK_DAYS = INPUT_TEXT_SEMICOLONS.split(';'); | ||
} | ||
|
||
@IsTest | ||
static void it_should_return_list_of_string_given_a_semi_colon_delimited_string() { | ||
List<SplitStringInvocable.Request> requests = new List<SplitStringInvocable.Request>(); | ||
SplitStringInvocable.Request request = new SplitStringInvocable.Request(); | ||
request.inputText = INPUT_TEXT_SEMICOLONS; | ||
request.delimiter = ';'; | ||
requests.add(request); | ||
|
||
Test.startTest(); | ||
|
||
List<List<String>> result = SplitStringInvocable.execute(requests); | ||
|
||
Test.stopTest(); | ||
|
||
System.Assert.isFalse(result.isEmpty()); | ||
System.Assert.areEqual(1, result.size()); | ||
|
||
List<String> stringList = result.get(0); | ||
System.Assert.isFalse(stringList.isEmpty()); | ||
System.Assert.areEqual(5, stringList.size()); | ||
System.Assert.areEqual(WEEK_DAYS, stringList); | ||
} | ||
|
||
@IsTest | ||
static void it_should_return_list_of_string_given_a_comma_delimited_string() { | ||
List<SplitStringInvocable.Request> requests = new List<SplitStringInvocable.Request>(); | ||
SplitStringInvocable.Request request = new SplitStringInvocable.Request(); | ||
request.inputText = INPUT_TEXT_COMMAS; | ||
request.delimiter = ','; | ||
requests.add(request); | ||
|
||
Test.startTest(); | ||
|
||
List<List<String>> result = SplitStringInvocable.execute(requests); | ||
|
||
Test.stopTest(); | ||
|
||
System.Assert.isFalse(result.isEmpty()); | ||
System.Assert.areEqual(1, result.size()); | ||
|
||
List<String> stringList = result.get(0); | ||
System.Assert.isFalse(stringList.isEmpty()); | ||
System.Assert.areEqual(5, stringList.size()); | ||
System.Assert.areEqual(WEEK_DAYS, stringList); | ||
} | ||
|
||
@IsTest | ||
static void it_should_handle_multiple_requests() { | ||
List<SplitStringInvocable.Request> requests = new List<SplitStringInvocable.Request>(); | ||
SplitStringInvocable.Request r1 = new SplitStringInvocable.Request(); | ||
r1.inputText = INPUT_TEXT_SEMICOLONS; | ||
r1.delimiter = ';'; | ||
requests.add(r1); | ||
SplitStringInvocable.Request r2 = new SplitStringInvocable.Request(); | ||
r2.inputText = INPUT_TEXT_COMMAS; | ||
r2.delimiter = ','; | ||
requests.add(r2); | ||
|
||
Test.startTest(); | ||
|
||
List<List<String>> result = SplitStringInvocable.execute(requests); | ||
|
||
Test.stopTest(); | ||
|
||
System.Assert.isFalse(result.isEmpty()); | ||
System.Assert.areEqual(2, result.size()); | ||
|
||
List<String> listOne = result.get(0); | ||
System.Assert.isFalse(listOne.isEmpty()); | ||
System.Assert.areEqual(5, listOne.size()); | ||
System.Assert.areEqual(WEEK_DAYS, listOne); | ||
|
||
List<String> listTwo = result.get(1); | ||
System.Assert.isFalse(listTwo.isEmpty()); | ||
System.Assert.areEqual(5, listTwo.size()); | ||
System.Assert.areEqual(WEEK_DAYS, listTwo); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
force-app/main/default/classes/SplitStringInvocableTest.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> |