Newer Version Available
Populate a Custom Big Object with Apex
You can create and update custom big object records in Apex using the Database.insertImmediate() method.
We recommend that you use the Apex String.trim() method to remove leading and trailing white space before you insert values, especially for values in primary key fields. This best practice ensures that SOQL queries on the big objects later work as you expect. When you specify an index field in a SOQL query WHERE clause, SOQL removes any leading or trailing white space before it compares it to the actual field value. Therefore, leading and trailing white space can’t be compared to values that have been stored. Even if your filter string matches the value that was inserted, no rows are matched by the filter.
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.
If a record insert fails, the Database.insertImmediate() method doesn’t throw an exception. Instead, it returns a SaveResult object that has a getErrors() method that returns a list of Database.Error objects. Each Database.Error object contains information about an error that occurred as a result of a failed record insert. See the Apex developer guide for more information about SaveResult and an example of iterating through the errors.