Newer Version Available
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.
Reinserting 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 exists doesn’t result in duplicates. Reinserting is helpful when uploading millions of records. If an error occurs, the reinsertion 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.
2PhoneBook__b pb = new PhoneBook__b();
3pb.FirstName__c = 'John';
4pb.LastName__c = 'Smith';
5pb.Address__c = '1 Market St';
6pb.PhoneNumber__c = '555-1212';
7database.insertImmediate(pb);
8// A single record will be created in the big object.1// Define the record with the same index values but different phone number.
2PhoneBook__b pb = new PhoneBook__b();
3pb.FirstName__c = 'John';
4pb.LastName__c = 'Smith';
5pb.Address__c = '1 Market St';
6pb.PhoneNumber__c = '415-555-1212';
7database.insertImmediate(pb);
8// The existing records will be "re-inserted". Only a single record will remain in the big object.1// Define the record with the different index values and different phone number
2PhoneBook__b pb = new PhoneBook__b();
3pb.FirstName__c = 'John';
4pb.LastName__c = 'Smith';
5pb.Address__c = 'Salesforce Tower';
6pb.PhoneNumber__c = '415-555-1212';
7database.insertImmediate(pb);
8// A new record will be created leaving two records in the big object.