Newer Version Available

This content describes an older version of this product. View Latest

Mock SOQL Tests for Data Cloud Data Model Objects

You can mock SOQL query responses for Data Cloud data model objects (DMOs) in Apex testing by using the new SOQL stub methods and a new test class. Use static or dynamic SOQL queries against DMOs and return mock records in a testing context.

Create mock test classes by extending the new System.SoqlStubProvider class and overriding the handleSoqlQuery() class method. Create DMO instances using either Test.createStubQueryRow() or Test.createStubQueryRows(). Register the mock provider in the test using Test.createSoqlStub() and execute the test code.

Apex governor limits apply to the stubbed records.

Note

The SOQL query must be against a DMO, either directly with a FROM clause or via a subquery. Also, these features are not allowed within a stub implementation:

  • SOQL
  • SOSL
  • Callouts
  • Future methods
  • Queueable Jobs
  • Batch Jobs
  • DML
  • Platform Events

This example shows a mock test class for the SkyMilesForBusinessOptInController class.