Newer Version Available

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

Populate a Custom Big Object with Apex

Use Apex to populate a custom big object.

You can create and update custom big object records in Apex using the insertImmediate method.

Any Apex tests that use DML calls will fail and potentially insert bad data into the target big object. This data won’t be deletable. To test DML calls, use a mocking framework with the Apex stub API to contain calls to the target big object.

Warning

Re-inserting a record with the same index but different data results in behavior similar to an upsert operation. If a record with the index exists, the insert overwrites the index values with the new data. Insertion is idempotent, so inserting data that already exists won't result in duplicates. Reinserting is helpful when uploading millions of records. If an error occurs, the reinsert reuploads the failed uploads without duplicate data. During the reinsertion, if no record exists for the provided index, a new record is inserted.

Here is an example of an insert operation in Apex that assumes a table in which the index consists of FirstName__c, LastName__c, and Address__c.
1<!-- Define the record -->
2<PhoneBook__b> pb = new PhoneBook__b();
3pb.FirstName__c = "John";
4pb.LastName__c = "Smith";
5pb.Address__c = "1 Market St";
6pb.PhoneNumber__c = "555-1212";
7
8<!-- Insert the record, which creates a new record -->
9database.insertImmediate(pb);
10
11<!-- Modify a field in the index -->
12pb.Address__c = "1 Market St, San Francisco, CA";
13
14<!-- Insert the record, creating a new record because the primary key has changed -->
15database.insertImmediate(pb);
16
17<!-- Modify a field not included in the index -->
18pb.PhoneNumber__c = "800-555-1212";
19
20<!-- Insert the record, which updates the second record because the index is the same -->
21database.insertImmediate(pb);