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