diff --git a/flow_action_components/GetNextFiveRecords/force-app/main/default/classes/GetNextFiveRecords.cls b/flow_action_components/GetNextFiveRecords/force-app/main/default/classes/GetNextFiveRecords.cls new file mode 100644 index 000000000..5fda170a1 --- /dev/null +++ b/flow_action_components/GetNextFiveRecords/force-app/main/default/classes/GetNextFiveRecords.cls @@ -0,0 +1,93 @@ +public with sharing class GetNextFiveRecords { + + @InvocableMethod(label='Get Next 5 Records') + public static List getRecords(List inputs) { + List outputs = new List(); + OutputVals output = new OutputVals(); + if (inputs.size() > 0) { + InputVals input = inputs[0]; + if (input.listOfRecs != null && input.counter != null && input.listOfRecs.size() >= input.counter) { + output.totalNumRecs = input.listOfRecs.size(); + integer currentCounter = input.counter; + integer endCounter = Math.min(currentCounter+5, input.listOfRecs.size()) - currentCounter; + output.newCounter = currentCounter + endCounter; + output.foundCount = endCounter; + output.percent = Math.round(currentCounter / output.totalNumRecs); + for (integer i = 0; i < endCounter; i++) { + + switch on (i) { + when 0 { + output.firstRec = input.listOfRecs[i+currentCounter]; + } + when 1 { + output.secondRec = input.listOfRecs[i+currentCounter]; + } + when 2 { + output.thirdRec = input.listOfRecs[i+currentCounter]; + } + when 3 { + output.fourthRec = input.listOfRecs[i+currentCounter]; + } + when 4 { + output.fifthRec = input.listOfRecs[i+currentCounter]; + } + } + + } + } else { + // empty list sent + output.totalNumRecs = -1; + output.newCounter = -1; + output.foundCount = -1; + output.percent = -1; + } + + + } else { + output.foundCount = -1; + output.newCounter = -1; + output.totalNumRecs = -1; + output.percent = -1; + } + outputs.add(output); + return outputs; + } + + public class InputVals{ + @InvocableVariable + public integer counter; + + @InvocableVariable + public List listOfRecs; + } + + public class OutputVals{ + @InvocableVariable + public integer totalNumRecs; + + @InvocableVariable + public integer foundCount; + + @InvocableVariable + public integer newCounter; + + @InvocableVariable + public SObject firstRec; + + @InvocableVariable + public SObject secondRec; + + @InvocableVariable + public SObject thirdRec; + + @InvocableVariable + public SObject fourthRec; + + @InvocableVariable + public SObject fifthRec; + + @InvocableVariable + public integer percent; + } + +} \ No newline at end of file diff --git a/flow_action_components/GetNextFiveRecords/force-app/main/default/classes/GetNextFiveRecords.cls-meta.xml b/flow_action_components/GetNextFiveRecords/force-app/main/default/classes/GetNextFiveRecords.cls-meta.xml new file mode 100644 index 000000000..f928c8e56 --- /dev/null +++ b/flow_action_components/GetNextFiveRecords/force-app/main/default/classes/GetNextFiveRecords.cls-meta.xml @@ -0,0 +1,5 @@ + + + 53.0 + Active + diff --git a/flow_action_components/GetNextFiveRecords/force-app/main/default/classes/GetNextFiveRecords_Test.cls b/flow_action_components/GetNextFiveRecords/force-app/main/default/classes/GetNextFiveRecords_Test.cls new file mode 100644 index 000000000..2e30c2f2b --- /dev/null +++ b/flow_action_components/GetNextFiveRecords/force-app/main/default/classes/GetNextFiveRecords_Test.cls @@ -0,0 +1,137 @@ +@isTest +public with sharing class GetNextFiveRecords_Test { + + + @isTest + public static void ValuesReturnedProperlyZero() { + + // make list of strings for the test methods + List listOfRequests = new List(); + for (integer i = 0; i < 7; i++) { + listOfRequests.add(new Account(name = 'This is my string ' + i)); + } + + List requests = new List(); + GetNextFiveRecords.InputVals request = new GetNextFiveRecords.InputVals(); + request.counter = 0; + request.listOfRecs = listOfRequests; + requests.add(request); + + Test.startTest(); + List responses = GetNextFiveRecords.getRecords(requests); + Test.stopTest(); + + // check outputs + System.assertNotEquals(responses.size(), 0); + if (responses.size() >0) { + GetNextFiveRecords.OutputVals response = responses[0]; + System.assertEquals(response.totalNumRecs, 7); + System.assertEquals(response.foundCount, 5); + System.assertEquals(response.newCounter, 5); + System.assertEquals(response.percent, 0/7); + System.assertEquals(response.firstRec, listOfRequests[0]); + System.assertEquals(response.secondRec, listOfRequests[1]); + System.assertEquals(response.thirdRec, listOfRequests[2]); + System.assertEquals(response.fourthRec, listOfRequests[3]); + System.assertEquals(response.fifthRec, listOfRequests[4]); + } + + } + + @isTest + public static void ValuesReturnedProperlyFour() { + + // make list of strings for the test methods + List listOfRequests = new List(); + for (integer i = 0; i < 7; i++) { + listOfRequests.add(new Account(name = 'This is my string ' + i)); + } + + List requests = new List(); + GetNextFiveRecords.InputVals request = new GetNextFiveRecords.InputVals(); + request.counter = 4; + request.listOfRecs = listOfRequests; + requests.add(request); + + Test.startTest(); + List responses = GetNextFiveRecords.getRecords(requests); + Test.stopTest(); + + // check outputs + System.assertNotEquals(responses.size(), 0); + if (responses.size() >0) { + GetNextFiveRecords.OutputVals response = responses[0]; + System.assertEquals(response.totalNumRecs, 7); + System.assertEquals(response.foundCount, 3); + System.assertEquals(response.newCounter, 7); + System.assertEquals(response.percent, 4/7); + System.assertEquals(response.firstRec, listOfRequests[4]); + System.assertEquals(response.secondRec, listOfRequests[5]); + System.assertEquals(response.thirdRec, listOfRequests[6]); + System.assertEquals(response.fourthRec, null); + System.assertEquals(response.fifthRec, null); + } + + } + + @isTest + public static void NoValuesReturned() { + + // make list of strings for the test methods + List listOfRequests = new List(); + for (integer i = 0; i < 7; i++) { + listOfRequests.add(new Account(name = 'This is my string ' + i)); + } + + List requests = new List(); + GetNextFiveRecords.InputVals request = new GetNextFiveRecords.InputVals(); + request.counter = 7; + request.listOfRecs = listOfRequests; + requests.add(request); + + Test.startTest(); + List responses = GetNextFiveRecords.getRecords(requests); + Test.stopTest(); + + // check outputs + System.assertNotEquals(responses.size(), 0); + if (responses.size() >0) { + GetNextFiveRecords.OutputVals response = responses[0]; + System.assertEquals(response.totalNumRecs, 7); + System.assertEquals(response.foundCount, 0); + System.assertEquals(response.newCounter, 7); + System.assertEquals(response.percent, 7/7); + System.assertEquals(response.firstRec, null); + System.assertEquals(response.secondRec, null); + System.assertEquals(response.thirdRec, null); + System.assertEquals(response.fourthRec, null); + System.assertEquals(response.fifthRec, null); + } + + } + + @isTest + public static void NoValuesGiven() { + List requests = new List(); + + Test.startTest(); + List responses = GetNextFiveRecords.getRecords(requests); + Test.stopTest(); + + // check outputs + System.assertNotEquals(responses.size(), 0); + if (responses.size() >0) { + GetNextFiveRecords.OutputVals response = responses[0]; + System.assertEquals(response.totalNumRecs, -1); + System.assertEquals(response.foundCount, -1); + System.assertEquals(response.newCounter, -1); + System.assertEquals(response.percent, -1); + System.assertEquals(response.firstRec, null); + System.assertEquals(response.secondRec, null); + System.assertEquals(response.thirdRec, null); + System.assertEquals(response.fourthRec, null); + System.assertEquals(response.fifthRec, null); + } + + } +} diff --git a/flow_action_components/GetNextFiveRecords/force-app/main/default/classes/GetNextFiveRecords_Test.cls-meta.xml b/flow_action_components/GetNextFiveRecords/force-app/main/default/classes/GetNextFiveRecords_Test.cls-meta.xml new file mode 100644 index 000000000..dd61d1f91 --- /dev/null +++ b/flow_action_components/GetNextFiveRecords/force-app/main/default/classes/GetNextFiveRecords_Test.cls-meta.xml @@ -0,0 +1,5 @@ + + + 52.0 + Active + diff --git a/flow_action_components/getAggregateSOQL/force-app/main/default/classes/getAggregateSOQL.cls b/flow_action_components/getAggregateSOQL/force-app/main/default/classes/getAggregateSOQL.cls new file mode 100644 index 000000000..653f74817 --- /dev/null +++ b/flow_action_components/getAggregateSOQL/force-app/main/default/classes/getAggregateSOQL.cls @@ -0,0 +1,32 @@ +public class getAggregateSOQL { + @InvocableMethod(label='Get Aggregate String List') + public static List> getRecords(List inputs) { + List outputs = new List(); + if (inputs.size() > 0) { + String query = inputs[0].query; + String fieldname = inputs[0].fieldname; + if (query.contains('group by')) { + List arlist = Database.query(query); + for (AggregateResult a : arlist) { + Object val = a.get(fieldname); + outputs.add(val.toString()); + } + } else { + // no results + } + } else { + // no results + } + List> finallist = new List>(); + finallist.add(outputs); + return finallist; + } + + public class InputVals{ + @InvocableVariable + public String query; + + @InvocableVariable + public String fieldname; + } +} \ No newline at end of file diff --git a/flow_action_components/getAggregateSOQL/force-app/main/default/classes/getAggregateSOQL.cls-meta.xml b/flow_action_components/getAggregateSOQL/force-app/main/default/classes/getAggregateSOQL.cls-meta.xml new file mode 100644 index 000000000..f928c8e56 --- /dev/null +++ b/flow_action_components/getAggregateSOQL/force-app/main/default/classes/getAggregateSOQL.cls-meta.xml @@ -0,0 +1,5 @@ + + + 53.0 + Active + diff --git a/flow_action_components/getAggregateSOQL/force-app/main/default/classes/getAggregateSOQL_Test.cls b/flow_action_components/getAggregateSOQL/force-app/main/default/classes/getAggregateSOQL_Test.cls new file mode 100644 index 000000000..f59ae6312 --- /dev/null +++ b/flow_action_components/getAggregateSOQL/force-app/main/default/classes/getAggregateSOQL_Test.cls @@ -0,0 +1,40 @@ +@isTest +public with sharing class getAggregateSOQL_Test { + + @TestSetup + static void makeData(){ + // make Account records to test + List acctlist = new List(); + for (integer i = 0; i < 10; i++) { + Account a = new Account(name='Test Account ' + Math.mod(i, 4)); + acctlist.add(a); + } + insert(acctlist); + } + + @isTest + public static void getAggregateSOQL_Test() { + + List requests = new List(); + getAggregateSOQL.InputVals request = new getAggregateSOQL.InputVals(); + request.query = 'select name, count(id) from Account group by name order by name'; + request.fieldname = 'name'; + requests.add(request); + + Test.startTest(); + List> responses = getAggregateSOQL.getRecords(requests); + Test.stopTest(); + + System.assertNotEquals(responses.size(), 0); + if (responses.size() >0) { + List response = responses[0]; + System.assertEquals(response.size(), 4); + for (integer i = 0; i < response.size(); i++) { + System.assertEquals(response[i], 'Test Account ' + i); + } + + } + + + } +} diff --git a/flow_action_components/getAggregateSOQL/force-app/main/default/classes/getAggregateSOQL_Test.cls-meta.xml b/flow_action_components/getAggregateSOQL/force-app/main/default/classes/getAggregateSOQL_Test.cls-meta.xml new file mode 100644 index 000000000..dd61d1f91 --- /dev/null +++ b/flow_action_components/getAggregateSOQL/force-app/main/default/classes/getAggregateSOQL_Test.cls-meta.xml @@ -0,0 +1,5 @@ + + + 52.0 + Active +