--- /dev/null
+/*
+ * SPDX-FileCopyrightText: 2024 Chris Duncan <chris@flowpex.dev>
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+global class System_Blob_valueOf {
+
+ @InvocableMethod(label='System.Blob.valueOf()' category='Flowpex System' iconName='slds:standard:default' description='Casts the specified String to a Blob.')
+
+ public static List<Response> System_Blob_valueOf (List<Request> requests) {
+ List<Response> responses = new List<Response>();
+ for (Request req : requests) {
+ Response res = new Response();
+ try {
+ res.blobOfString = System.Blob.valueOf(req.stringToBlob);
+ } catch (Exception e) {
+ System.debug(e);
+ }
+ responses.add(res);
+ }
+ return responses;
+ }
+
+ public class Request {
+ @InvocableVariable(required='true' label='String to blob' description='')
+ public String stringToBlob;
+
+ public Request () {}
+ public Request (String s) {
+ this.stringToBlob = s;
+ }
+ }
+
+ public class Response {
+ @InvocableVariable(label='Blob' description='')
+ public Blob blobOfString;
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * SPDX-FileCopyrightText: 2024 Chris Duncan <chris@flowpex.dev>
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+@isTest
+private class System_Blob_valueOf_TEST {
+
+ @isTest
+ static void testNoArgs () {
+ List<System_Blob_valueOf.Request> requests = new List<System_Blob_valueOf.Request>();
+
+ Test.startTest();
+ List<System_Blob_valueOf.Response> responses = System_Blob_valueOf.System_Blob_valueOf(requests);
+ Test.stopTest();
+
+ Assert.areEqual(0, responses.size());
+ }
+
+ @isTest
+ static void testEmptyRequest () {
+ List<System_Blob_valueOf.Request> requests = new List<System_Blob_valueOf.Request>();
+ System_Blob_valueOf.Request req = new System_Blob_valueOf.Request();
+ requests.add(req);
+
+ Test.startTest();
+ List<System_Blob_valueOf.Response> responses = System_Blob_valueOf.System_Blob_valueOf(requests);
+ Test.stopTest();
+
+ Assert.areEqual(1, responses.size());
+ System_Blob_valueOf.Response res = responses[0];
+ Assert.areEqual(null, res.blobOfString);
+ }
+
+ @isTest
+ static void testBlankArg () {
+ List<System_Blob_valueOf.Request> requests = new List<System_Blob_valueOf.Request>();
+ System_Blob_valueOf.Request req = new System_Blob_valueOf.Request('');
+ requests.add(req);
+
+ Test.startTest();
+ List<System_Blob_valueOf.Response> responses = System_Blob_valueOf.System_Blob_valueOf(requests);
+ Test.stopTest();
+
+ Assert.areEqual(1, responses.size());
+ System_Blob_valueOf.Response res = responses[0];
+ Assert.areNotEqual(null, res.blobOfString);
+ Assert.areEqual(0, res.blobOfString.size());
+ }
+
+ @isTest
+ static void testManyArgs () {
+ List<String> stringList = new List<String>();
+ for (Integer i = 0; i < 10; i++) {
+ stringList.add(i.toString());
+ }
+
+ Test.startTest();
+ List<System_Blob_valueOf.Request> requests = new List<System_Blob_valueOf.Request>();
+ for (String s : stringList) {
+ System_Blob_valueOf.Request req = new System_Blob_valueOf.Request(s);
+ requests.add(req);
+ }
+ List<System_Blob_valueOf.Response> responses = System_Blob_valueOf.System_Blob_valueOf(requests);
+ Test.stopTest();
+
+ Assert.areEqual(10, responses.size());
+ for (System_Blob_valueOf.Response res : responses) {
+ Assert.areNotEqual(null, res.blobOfString);
+ }
+ }
+}
\ No newline at end of file