diff --git a/force-app/main/default/classes/SplitStringInvocable.cls b/force-app/main/default/classes/SplitStringInvocable.cls new file mode 100644 index 0000000..445ae84 --- /dev/null +++ b/force-app/main/default/classes/SplitStringInvocable.cls @@ -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> execute(List requests) { + List> output = new List>(); + 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 = ';'; + } +} diff --git a/force-app/main/default/classes/SplitStringInvocable.cls-meta.xml b/force-app/main/default/classes/SplitStringInvocable.cls-meta.xml new file mode 100644 index 0000000..c14e405 --- /dev/null +++ b/force-app/main/default/classes/SplitStringInvocable.cls-meta.xml @@ -0,0 +1,5 @@ + + + 59.0 + Active + diff --git a/force-app/main/default/classes/SplitStringInvocableTest.cls b/force-app/main/default/classes/SplitStringInvocableTest.cls new file mode 100644 index 0000000..537bb3b --- /dev/null +++ b/force-app/main/default/classes/SplitStringInvocableTest.cls @@ -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 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 requests = new List(); + SplitStringInvocable.Request request = new SplitStringInvocable.Request(); + request.inputText = INPUT_TEXT_SEMICOLONS; + request.delimiter = ';'; + requests.add(request); + + Test.startTest(); + + List> result = SplitStringInvocable.execute(requests); + + Test.stopTest(); + + System.Assert.isFalse(result.isEmpty()); + System.Assert.areEqual(1, result.size()); + + List 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 requests = new List(); + SplitStringInvocable.Request request = new SplitStringInvocable.Request(); + request.inputText = INPUT_TEXT_COMMAS; + request.delimiter = ','; + requests.add(request); + + Test.startTest(); + + List> result = SplitStringInvocable.execute(requests); + + Test.stopTest(); + + System.Assert.isFalse(result.isEmpty()); + System.Assert.areEqual(1, result.size()); + + List 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 requests = new List(); + 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> result = SplitStringInvocable.execute(requests); + + Test.stopTest(); + + System.Assert.isFalse(result.isEmpty()); + System.Assert.areEqual(2, result.size()); + + List listOne = result.get(0); + System.Assert.isFalse(listOne.isEmpty()); + System.Assert.areEqual(5, listOne.size()); + System.Assert.areEqual(WEEK_DAYS, listOne); + + List listTwo = result.get(1); + System.Assert.isFalse(listTwo.isEmpty()); + System.Assert.areEqual(5, listTwo.size()); + System.Assert.areEqual(WEEK_DAYS, listTwo); + } +} diff --git a/force-app/main/default/classes/SplitStringInvocableTest.cls-meta.xml b/force-app/main/default/classes/SplitStringInvocableTest.cls-meta.xml new file mode 100644 index 0000000..c14e405 --- /dev/null +++ b/force-app/main/default/classes/SplitStringInvocableTest.cls-meta.xml @@ -0,0 +1,5 @@ + + + 59.0 + Active +