Skip to content

Validate SObject types in getFirstRecord input list#6

Draft
Copilot wants to merge 2 commits into
mainfrom
copilot/validate-sobject-types-input-list
Draft

Validate SObject types in getFirstRecord input list#6
Copilot wants to merge 2 commits into
mainfrom
copilot/validate-sobject-types-input-list

Conversation

Copy link
Copy Markdown

Copilot AI commented Apr 3, 2026

Passing a mixed-type SObject list to getFirstRecord could cause silent casting failures downstream. This adds type homogeneity validation before returning the first record.

Changes

CollectionGetFirstRecord_Records.cls

  • Iterates the input list and compares each record's getSObjectType() against the first record's type
  • Null records within the list are treated as invalid (trigger the mixed-type path)
  • On type mismatch: sets record = null and populates a new errorMessage field
  • Added errorMessage as an @InvocableVariable on Response so Flow builders can surface the error

CollectionGetFirstRecord_RecordsTest.cls

  • Added testGetFirstRecord_MixedSObjectTypesReturnsNullWithError — passes an Account + Contact in the same list, asserts record is null and errorMessage is set

Behavior

// Mixed types → null record + error message
Request req = new Request();
req.records = new List<SObject>{ account, contact };

Response resp = getFirstRecord(new List<Request>{ req })[0];
// resp.record       → null
// resp.errorMessage → 'Mixed SObject types detected in the input list...'

Copilot AI linked an issue Apr 3, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Add validation for SObject types in input list Validate SObject types in getFirstRecord input list Apr 3, 2026
Copilot AI requested a review from ethandunzer April 3, 2026 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Validate SObject Types in Input List

2 participants