Creating BigObject Record in Test Class Using Test.loadData(..)

Successfully used testLoadData for a number of test classes for “regular” Sobjects. Have seen references to Stub Api Mocking Framework for one method to create test records for Big Objects in Apex but seems pretty advanced.

Is there a way to use the Static Resource and use Test.loadData(..) as documented here to add Big Object records for test classes? TestloadData(BigObjectName.Sobjecttype, 'Filename') does not seem to be working. Getting error:

Unknown field: xyz


I’m currently working with big objects, and I don’t think this is possible. Simply put, you cannot insert or delete big objects in unit tests.

Salesforce documents this somewhat here:

I quote:

Apex tests that use mixed DML calls are not allowed and fail. If you write only to the Big Object, the test inserts bad data into the target big object that you have to delete manually. To contain test DML calls to the target big object, use a mocking framework with the batch Apex stub API instead.

I could not use the Apex stub API to mock big object insert (given that I would have to stub the calls in the Database namespace, which is not possible). The only solution avaliable to me is to isolate the database insert/delete operations in a separate interface. Have an implementation for production and a mock implementation for tests that persists the object in-memory instead. Very cumbersome and annoying.

Source : Link , Question Author : ddeve , Answer Author : mkorman

Leave a Comment