From 07f0e34d18f8171fff90421427455db411df14f0 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 3 Apr 2026 17:51:47 +0000 Subject: [PATCH 1/2] Initial plan From df57a871b3e8c6f1b6c6aa7903dd1d74902521be Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 3 Apr 2026 17:53:28 +0000 Subject: [PATCH 2/2] Add null/type validation for records list entries and fieldApiName Agent-Logs-Url: https://github.com/edunzer/CollectionGetFirstValue_Records/sessions/df62ad14-9167-493f-8333-0b8fd315c8e4 Co-authored-by: ethandunzer <180557240+ethandunzer@users.noreply.github.com> --- .../CollectionGetFirstValue_Records.cls | 7 +++ .../CollectionGetFirstValue_RecordsTest.cls | 46 +++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/force-app/main/default/classes/CollectionGetFirstValue_Records.cls b/force-app/main/default/classes/CollectionGetFirstValue_Records.cls index 65c2537..eb05e7d 100644 --- a/force-app/main/default/classes/CollectionGetFirstValue_Records.cls +++ b/force-app/main/default/classes/CollectionGetFirstValue_Records.cls @@ -14,6 +14,13 @@ public with sharing class CollectionGetFirstValue_Records { } SObject firstRecord = req.records[0]; + + if (firstRecord == null || String.isBlank(req.fieldApiName)) { + resp.response = null; + results.add(resp); + continue; + } + Object fieldValue = firstRecord.get(req.fieldApiName); resp.response = (fieldValue == null) ? null : String.valueOf(fieldValue); diff --git a/force-app/main/default/classes/CollectionGetFirstValue_RecordsTest.cls b/force-app/main/default/classes/CollectionGetFirstValue_RecordsTest.cls index 4008110..cb9d3b6 100644 --- a/force-app/main/default/classes/CollectionGetFirstValue_RecordsTest.cls +++ b/force-app/main/default/classes/CollectionGetFirstValue_RecordsTest.cls @@ -49,4 +49,50 @@ public with sharing class CollectionGetFirstValue_RecordsTest { System.assertEquals(null, responses[0].response, 'Null records should result in null response'); } + @IsTest + static void testGetFirstValue_NullFirstRecord() { + CollectionGetFirstValue_Records.Request req = new CollectionGetFirstValue_Records.Request(); + req.records = new List{ null }; + req.fieldApiName = 'Name'; + + List requests = new List{ req }; + + List responses = CollectionGetFirstValue_Records.getFirstValue(requests); + + System.assertEquals(1, responses.size()); + System.assertEquals(null, responses[0].response, 'Null first record should result in null response'); + } + + @IsTest + static void testGetFirstValue_NullFieldApiName() { + Account a = new Account(Name = 'Test Account'); + + CollectionGetFirstValue_Records.Request req = new CollectionGetFirstValue_Records.Request(); + req.records = new List{ a }; + req.fieldApiName = null; + + List requests = new List{ req }; + + List responses = CollectionGetFirstValue_Records.getFirstValue(requests); + + System.assertEquals(1, responses.size()); + System.assertEquals(null, responses[0].response, 'Null fieldApiName should result in null response'); + } + + @IsTest + static void testGetFirstValue_BlankFieldApiName() { + Account a = new Account(Name = 'Test Account'); + + CollectionGetFirstValue_Records.Request req = new CollectionGetFirstValue_Records.Request(); + req.records = new List{ a }; + req.fieldApiName = ' '; + + List requests = new List{ req }; + + List responses = CollectionGetFirstValue_Records.getFirstValue(requests); + + System.assertEquals(1, responses.size()); + System.assertEquals(null, responses[0].response, 'Blank fieldApiName should result in null response'); + } + } \ No newline at end of file