5

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

3
  • 1
    Big Objects and SObjects have different characteristics. Test.loadData(..) is specific to load test data for SObjects only. If it's not documented to support Big Objects, you will not be able to load test data using this approach. – Jayant Das Jan 23 '19 at 23:24
  • 1
    fflib Selector layer and apexmocks would be how I would go about this – cropredy Jan 23 '19 at 23:35
  • Big Objects are CustomObjects as far as Metadata API. Only diff is __b – ddeve Jan 24 '19 at 3:32
1

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: https://developer.salesforce.com/docs/atlas.en-us.bigobjects.meta/bigobjects/big_object_populate_apex.htm

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.