Salesforce has a limitation on performing queries on a large number of records. Especially when your data is massive performing queries and the performance of the system downgrades. That is where Big Object Comes into the picture.
Big Objects allows us to store very large volumes of data (billions of records) in the Salesforce cloud without compromising performance. A big object provides consistent performance, whether you have 1 million records, 100 million, or even 1 billion.
Salesforce Big Objects important points:
- Stored in a non-relational database
- Suffix “__b” for custom objects
- up to 1 billion
- No support for triggers, processes, or flows
- Support only object & fields level permissions
- Limited SOQL + Async SOQL
- Read only after creation (metadata)
Types of BigObject: There are two types of BigObject:
- Standard BigObjects: Standard BigObjects are defined by Salesforce. For example, FieldHistoryArchive BigObject stores data as part of the Field Audit Trail product.
- Custom BigObjects: Custom Bigobject is created by the user according to the requirement. We can create BigObject in two ways
- A big object can be created from ⚙️ Setup → Big Objects → New
- A big object can be created from ⚙️ Setup → Big Objects → New
- Add the custom field by clicking the New button
- Once you have created your required custom fields, you can create your index. The index field is unique.
How to Create Big Objects with Metadata API
To create the big objects from Metadata API we need an object file that contains the following:
- Object Files: Create a file that contains definitions of big objects, fields, and indexes.
- PermissionSet/Profile Files: This is not the required file but this file is used to assign the object and field permissions. This grants big object access to the user because by default big objects are restricted.
- Package File: A file for the deployment of metadata definitions and permission.
FormCruiseCallbackTransID__b.object- <?XMLversion=”1.0″encoding=”UTF-8″?>
- <CustomObjectxmlns=”http://soap.sforce.com/2006/04/metadata”>
- <deploymentStatus>Deployed</deploymentStatus>
- <fields>
- <fullName>CanBeMerged__c</fullName>
- <label>CanBeMerged</label>
- <length>80</length>
- <type>Text</type>
- </fields>
- <fields>
- <fullName>CodeReviewDate__c</fullName>
- <label>CodeReviewDate</label>
- <type>DateTime</type>
- <required>true</required>
- </fields>
- <fields>
- <fullName>Comments__c</fullName>
- <label>Comments</label>
- <length>255</length>
- <type>Text</type>
- </fields>
- <fields>
- <fullName>Employee__c</fullName>
- <label>Employee</label>
- <referenceTo>Employee__c</referenceTo>
- <relationshipName>Employees</relationshipName>
- <required>true</required>
- <type>Lookup</type>
- </fields>
- <fields>
- <fullName>Score__c</fullName>
- <label>Score</label>
- <precision>1</precision>
- <scale>0</scale>
- <type>Number</type>
- </fields>
- <fields>
- <fullName>Story__c</fullName>
- <label>Story__c</label>
- <referenceTo>Story__c</referenceTo>
- <relationshipName>Stories</relationshipName>
- <required>true</required>
- <type>Lookup</type>
- </fields>
- <indexes>
- <type>PRIMARY</type>
- <fullName>Test1CodeReviewPK</fullName>
- <fields>
- <name>Story__c</name>
- <sortDirection>DESC</sortDirection>
- </fields>
- <fields>
- <name>Employee__c</name>
- <sortDirection>DESC</sortDirection>
- </fields>
- <fields>
- <name>CodeReviewDate__c</name>
- <sortDirection>DESC</sortDirection>
- </fields>
- </indexes>
- <label>CodeReviewHistory</label>
- <pluralLabel>CodeReviewsHistory</pluralLabel>
- </CustomObject>
- <?xmlversion=”1.0″encoding=”UTF-8″?>
- <Packagexmlns=”http://soap.sforce.com/2006/04/metadata”>
- <types>
- <members>*</members>
- <name>CustomObject</name>
- </types>
- <types>
- <members>*</members>
- <name>PermissionSet</name>
- </types>
- <version>39.0</version>
- </Package>
- <?xmlversion=”1.0″encoding=”UTF-8″?>
- <PermissionSetxmlns=”http://soap.sforce.com/2006/04/metadata”>
- <fieldPermissions>
- <editable>true</editable>
- <field>FormCruiseCallbackTransID_b.CodeReviewDate__c</field>
- <readable>true</readable>
- </fieldPermissions>
- <fieldPermissions>
- <editable>true</editable>
- <field>Test1CodeReview__b.Employee__c</field>
- <readable>true</readable>
- </fieldPermissions>
- <fieldPermissions>
- <editable>true</editable>
- <field>Test1CodeReview__b.Story__c</field>
- <readable>true</readable>
- </fieldPermissions>
- <fieldPermissions>
- <editable>true</editable>
- <field>Test1CodeReview__b.CanBeMerged__c</field>
- <readable>true</readable>
- </fieldPermissions>
- <fieldPermissions>
- <editable>true</editable>
- <field>Test1CodeReview__b.Score__c</field>
- <readable>true</readable>
- </fieldPermissions>
- </PermissionSet>
package.xml
FormCruiseCallbackTransID_BigObject.PermissionSet
Deploy Custom BigObjects as a Metadata Package:
Compress all the files above as zip file which contains the compressed components. Deploying using Workbench:
To deploy the big object, we need to create the following structure of the files.
- Create a folder “objects” and move the .object file to this folder.
- Create a folder “permissionSets” and move the .permissionSet file to this folder.
- Finally create a zip file with objects folder, permissionSets folder, and package.xml file.
- a) Go to https://workbench.developerforce.com and login with the org credentials.
- b) Go to the migration and Deploy.
Creating records for BigObject:
- Test1CodeReview__b tr = new Test1CodeReview__b();
- cr.CanBeMerged__c = ’False’;
- cr.CodeReviewDate__c = System.today();
- cr.Comments__c = ’I found a SOQL inside of a loop.’;
- cr.Employee__c = ’a6j24000000fxSL’;
- cr.Score__c = 0;
- cr.Story__c = ’a6k24000000k9bN’;
- database.insertImmediate(cr);
Points to remember
- The order of the index fields is very important as this impacts the SOQL queries that can be executed on the big object.
- Once the Index field is created cant be modified.
- triggers, processes, and flows cant be created