Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@ public with sharing class CollectionGetFirstRecord_Records {
for (Request req : requests) {
Response resp = new Response();

if (req.records == null || req.records.isEmpty()) {
if (req.records == null) {
resp.record = null;
resp.errorMessage = 'Input list was null';
results.add(resp);
continue;
}

if (req.records.isEmpty()) {
resp.record = null;
resp.errorMessage = 'Input list was empty';
results.add(resp);
continue;
}
Expand All @@ -27,5 +35,7 @@ public with sharing class CollectionGetFirstRecord_Records {
public class Response {
@InvocableVariable(label='Record' description='The first record from the provided collection')
public SObject record;
@InvocableVariable(label='Error Message' description='Description of why no record was returned, when applicable')
public String errorMessage;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ private class CollectionGetFirstRecord_RecordsTest {

System.assertEquals(1, responses.size(), 'Should return one response per request');
System.assertNotEquals(null, responses[0].record, 'Record should not be null');
System.assertEquals(null, responses[0].errorMessage, 'No error message should be set for a valid list');

Account returned = (Account) responses[0].record;
System.assertEquals(a1.Id, returned.Id, 'Should return the first account inserted');
Expand All @@ -43,6 +44,8 @@ private class CollectionGetFirstRecord_RecordsTest {

System.assertEquals(2, responses.size(), 'Should return two responses');
System.assertEquals(null, responses[0].record, 'Empty list should yield null record');
System.assertEquals('Input list was empty', responses[0].errorMessage, 'Empty list should set appropriate error message');
System.assertEquals(null, responses[1].record, 'Null list should yield null record');
System.assertEquals('Input list was null', responses[1].errorMessage, 'Null list should set appropriate error message');
}
}