]> git.codecow.com Git - flowpex.git/commitdiff
Add System.Blob.valueOf()
authorChris Duncan <chris@flowpex.dev>
Mon, 24 Jun 2024 06:47:13 +0000 (23:47 -0700)
committerChris Duncan <chris@flowpex.dev>
Mon, 24 Jun 2024 06:47:13 +0000 (23:47 -0700)
src/System/Blob/valueOf/System_Blob_valueOf.cls [new file with mode: 0644]
src/System/Blob/valueOf/System_Blob_valueOf.cls-meta.xml [new file with mode: 0644]
src/System/Blob/valueOf/System_Blob_valueOf_TEST.cls [new file with mode: 0644]
src/System/Blob/valueOf/System_Blob_valueOf_TEST.cls-meta.xml [new file with mode: 0644]

diff --git a/src/System/Blob/valueOf/System_Blob_valueOf.cls b/src/System/Blob/valueOf/System_Blob_valueOf.cls
new file mode 100644 (file)
index 0000000..d5d500d
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * 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
diff --git a/src/System/Blob/valueOf/System_Blob_valueOf.cls-meta.xml b/src/System/Blob/valueOf/System_Blob_valueOf.cls-meta.xml
new file mode 100644 (file)
index 0000000..ff0b65f
--- /dev/null
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+SPDX-FileCopyrightText: 2024 Chris Duncan <chris@flowpex.dev>
+SPDX-License-Identifier: GPL-3.0-or-later
+-->
+<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
+    <apiVersion>61.0</apiVersion>
+    <status>Active</status>
+</ApexClass>
\ No newline at end of file
diff --git a/src/System/Blob/valueOf/System_Blob_valueOf_TEST.cls b/src/System/Blob/valueOf/System_Blob_valueOf_TEST.cls
new file mode 100644 (file)
index 0000000..631326d
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * 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
diff --git a/src/System/Blob/valueOf/System_Blob_valueOf_TEST.cls-meta.xml b/src/System/Blob/valueOf/System_Blob_valueOf_TEST.cls-meta.xml
new file mode 100644 (file)
index 0000000..ff0b65f
--- /dev/null
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+SPDX-FileCopyrightText: 2024 Chris Duncan <chris@flowpex.dev>
+SPDX-License-Identifier: GPL-3.0-or-later
+-->
+<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
+    <apiVersion>61.0</apiVersion>
+    <status>Active</status>
+</ApexClass>
\ No newline at end of file