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 @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<SObject>{ null };
req.fieldApiName = 'Name';

List<CollectionGetFirstValue_Records.Request> requests = new List<CollectionGetFirstValue_Records.Request>{ req };

List<CollectionGetFirstValue_Records.Response> 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<SObject>{ a };
req.fieldApiName = null;

List<CollectionGetFirstValue_Records.Request> requests = new List<CollectionGetFirstValue_Records.Request>{ req };

List<CollectionGetFirstValue_Records.Response> 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<SObject>{ a };
req.fieldApiName = ' ';

List<CollectionGetFirstValue_Records.Request> requests = new List<CollectionGetFirstValue_Records.Request>{ req };

List<CollectionGetFirstValue_Records.Response> responses = CollectionGetFirstValue_Records.getFirstValue(requests);

System.assertEquals(1, responses.size());
System.assertEquals(null, responses[0].response, 'Blank fieldApiName should result in null response');
}

}