Skip to content

Ensure that sobject type is correctly determined for SObject collections#33

Merged
pgajek2 merged 1 commit intobeyond-the-cloud-dev:release/v3.1.0from
tom-gangemi:fix/handle-sobject-collection-type
Feb 18, 2026
Merged

Ensure that sobject type is correctly determined for SObject collections#33
pgajek2 merged 1 commit intobeyond-the-cloud-dev:release/v3.1.0from
tom-gangemi:fix/handle-sobject-collection-type

Conversation

@tom-gangemi
Copy link
Contributor

Description

  • As of v3, passing a record collection of type SObject[] to toUpsert and toUpdate methods no longer works as expected
    • This is due to calling getSObjectType() on the collection
    • Resulting in Result.upsertsOf not returning records for a given SObject type
  • This change implements a new method resolveObjectType(List<SObject> records)
    • This finds the first available type from the collection whilst ensuring mixed types have not been provided
    • This implementation is based on the same assumption that setObjectTypeBasedOnIds makes (which is that mixed types will not be handled)

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Code refactoring
  • Test improvements
  • CI/CD improvements

Changes Made

  • Add resolveObjectType method and use it in DmlRecords constructor
  • global Commitable toUpsert(List<SObject> records, SObjectField externalIdField) now uses Records(records); to ensure correct sobject type

Related Issues

Fixes #
Closes #

Testing

  • All existing tests pass (npm test)
  • Added new tests for new functionality
  • Tested in scratch org
  • Linting passes (npm run lint)
  • Code formatting is correct (npm run prettier:verify)

Screenshots

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code where necessary
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings or errors
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published

Additional Notes

@vercel
Copy link

vercel bot commented Feb 18, 2026

@tom-gangemi is attempting to deploy a commit to the Beyond The Cloud Team on Vercel.

A member of the Team first needs to authorize it.

@tom-gangemi tom-gangemi marked this pull request as draft February 18, 2026 09:34
@tom-gangemi tom-gangemi marked this pull request as ready for review February 18, 2026 09:34
@tom-gangemi
Copy link
Contributor Author

Almost forgot. Here's an apex anon snippet to illustrate.

DML.mock('Example').allDmls();

SObject[] recordsToUpsert = new SObject[]{new Contact()};

DML.Result result = new DML()
    .toUpsert(recordsToUpsert)
    .identifier('Example')
    .commitWork();

DML.OperationResult op = result.upsertsOf(Contact.getSObjectType());
System.debug(op.recordResults().size()); // Expected 1. Got 0

@pgajek2 pgajek2 changed the base branch from main to release/v3.1.0 February 18, 2026 13:13
@pgajek2
Copy link
Member

pgajek2 commented Feb 18, 2026

Hi @tom-gangemi , great job!

I'll push it as a part of the release/v3.1.0 to follow the release process.

@pgajek2 pgajek2 merged commit df9aab9 into beyond-the-cloud-dev:release/v3.1.0 Feb 18, 2026
0 of 2 checks passed
@pgajek2 pgajek2 mentioned this pull request Feb 18, 2026
20 tasks
@tom-gangemi
Copy link
Contributor Author

Happy to help!

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.

2 participants