--- /dev/null
+/*
+ * SPDX-FileCopyrightText: 2024 Chris Duncan <chris@flowpex.dev>
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+global class System_Blob_toPdf {
+
+ @InvocableMethod(label='System.Blob.toPdf()' category='Flowpex System' iconName='slds:standard:form' description='Creates a binary object out of the given string, encoding it as a PDF file.')
+
+ public static List<Response> System_Blob_toPdf (List<Request> requests) {
+ List<Response> responses = new List<Response>();
+ for (Request req : requests) {
+ Response res = new Response();
+ try {
+ if (req.stringToPdf != null) {
+ res.pdfOfString = System.Blob.toPdf(req.stringToPdf);
+ }
+ } catch (Exception e) {
+ System.debug(e);
+ }
+ responses.add(res);
+ }
+ return responses;
+ }
+
+ public class Request {
+ @InvocableVariable(required='true' label='String to PDF' description='')
+ public String stringToPdf;
+
+ public Request () {}
+ public Request (String s) {
+ this.stringToPdf = s;
+ }
+ }
+
+ public class Response {
+ @InvocableVariable(label='PDF' description='')
+ public Blob pdfOfString;
+ }
+}
\ 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_toPdf_TEST {
+
+ @isTest
+ static void testNoArgs () {
+ List<System_Blob_toPdf.Request> requests = new List<System_Blob_toPdf.Request>();
+
+ Test.startTest();
+ List<System_Blob_toPdf.Response> responses = System_Blob_toPdf.System_Blob_toPdf(requests);
+ Test.stopTest();
+
+ Assert.areEqual(0, responses.size());
+ }
+
+ @isTest
+ static void testEmptyRequest () {
+ List<System_Blob_toPdf.Request> requests = new List<System_Blob_toPdf.Request>();
+ System_Blob_toPdf.Request req = new System_Blob_toPdf.Request();
+ requests.add(req);
+
+ Test.startTest();
+ List<System_Blob_toPdf.Response> responses = System_Blob_toPdf.System_Blob_toPdf(requests);
+ Test.stopTest();
+
+ Assert.areEqual(1, responses.size());
+ System_Blob_toPdf.Response res = responses[0];
+ Assert.areEqual(null, res.pdfOfString);
+ }
+
+ @isTest
+ static void testBlankArg () {
+ List<System_Blob_toPdf.Request> requests = new List<System_Blob_toPdf.Request>();
+ System_Blob_toPdf.Request req = new System_Blob_toPdf.Request('');
+ requests.add(req);
+
+ Test.startTest();
+ List<System_Blob_toPdf.Response> responses = System_Blob_toPdf.System_Blob_toPdf(requests);
+ Test.stopTest();
+
+ Assert.areEqual(1, responses.size());
+ System_Blob_toPdf.Response res = responses[0];
+ Assert.areEqual(null, res.pdfOfString);
+ }
+
+ @isTest
+ static void testWhitespaceArg () {
+ List<System_Blob_toPdf.Request> requests = new List<System_Blob_toPdf.Request>();
+ System_Blob_toPdf.Request req = new System_Blob_toPdf.Request(' ');
+ requests.add(req);
+
+ Test.startTest();
+ List<System_Blob_toPdf.Response> responses = System_Blob_toPdf.System_Blob_toPdf(requests);
+ Test.stopTest();
+
+ Assert.areEqual(1, responses.size());
+ System_Blob_toPdf.Response res = responses[0];
+ Assert.areNotEqual(null, res.pdfOfString);
+ }
+
+ @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_toPdf.Request> requests = new List<System_Blob_toPdf.Request>();
+ for (String s : stringList) {
+ System_Blob_toPdf.Request req = new System_Blob_toPdf.Request(s);
+ requests.add(req);
+ }
+ List<System_Blob_toPdf.Response> responses = System_Blob_toPdf.System_Blob_toPdf(requests);
+ Test.stopTest();
+
+ Assert.areEqual(10, responses.size());
+ for (System_Blob_toPdf.Response res : responses) {
+ Assert.areNotEqual(null, res.pdfOfString);
+ }
+ }
+}
\ No newline at end of file