Salesforce Big Objects Introduction

|
| By Webner

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:

  1. Stored in a non-relational database
  2. Suffix “__b” for custom objects
  3. up to 1 billion
  4. No support for triggers, processes, or flows
  5. Support only object & fields level permissions
  6. Limited SOQL + Async SOQL
  7. 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
      bigObject
  • Add the custom field by clicking the New button
    bigObject1
  • 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

    1. <?XMLversion=”1.0″encoding=”UTF-8″?>
    2. <CustomObjectxmlns=”http://soap.sforce.com/2006/04/metadata”>
    3. <deploymentStatus>Deployed</deploymentStatus>
    4. <fields>
    5. <fullName>CanBeMerged__c</fullName>
    6. <label>CanBeMerged</label>
    7. <length>80</length>
    8. <type>Text</type>
    9. </fields>
    10. <fields>
    11. <fullName>CodeReviewDate__c</fullName>
    12. <label>CodeReviewDate</label>
    13. <type>DateTime</type>
    14. <required>true</required>
    15. </fields>
    16. <fields>
    17. <fullName>Comments__c</fullName>
    18. <label>Comments</label>
    19. <length>255</length>
    20. <type>Text</type>
    21. </fields>
    22. <fields>
    23. <fullName>Employee__c</fullName>
    24. <label>Employee</label>
    25. <referenceTo>Employee__c</referenceTo>
    26. <relationshipName>Employees</relationshipName>
    27. <required>true</required>
    28. <type>Lookup</type>
    29. </fields>
    30. <fields>
    31. <fullName>Score__c</fullName>
    32. <label>Score</label>
    33. <precision>1</precision>
    34. <scale>0</scale>
    35. <type>Number</type>
    36. </fields>
    37. <fields>
    38. <fullName>Story__c</fullName>
    39. <label>Story__c</label>
    40. <referenceTo>Story__c</referenceTo>
    41. <relationshipName>Stories</relationshipName>
    42. <required>true</required>
    43. <type>Lookup</type>
    44. </fields>
    45. <indexes>
    46. <type>PRIMARY</type>
    47. <fullName>Test1CodeReviewPK</fullName>
    48. <fields>
    49. <name>Story__c</name>
    50. <sortDirection>DESC</sortDirection>
    51. </fields>
    52. <fields>
    53. <name>Employee__c</name>
    54. <sortDirection>DESC</sortDirection>
    55. </fields>
    56. <fields>
    57. <name>CodeReviewDate__c</name>
    58. <sortDirection>DESC</sortDirection>
    59. </fields>
    60. </indexes>
    61. <label>CodeReviewHistory</label>
    62. <pluralLabel>CodeReviewsHistory</pluralLabel>
    63. </CustomObject>

    package.xml

    1. <?xmlversion=”1.0″encoding=”UTF-8″?>
    2. <Packagexmlns=”http://soap.sforce.com/2006/04/metadata”>
    3. <types>
    4. <members>*</members>
    5. <name>CustomObject</name>
    6. </types>
    7. <types>
    8. <members>*</members>
    9. <name>PermissionSet</name>
    10. </types>
    11. <version>39.0</version>
    12. </Package>

    FormCruiseCallbackTransID_BigObject.PermissionSet

    1. <?xmlversion=”1.0″encoding=”UTF-8″?>
    2. <PermissionSetxmlns=”http://soap.sforce.com/2006/04/metadata”>
    3. <fieldPermissions>
    4. <editable>true</editable>
    5. <field>FormCruiseCallbackTransID_b.CodeReviewDate__c</field>
    6. <readable>true</readable>
    7. </fieldPermissions>
    8. <fieldPermissions>
    9. <editable>true</editable>
    10. <field>Test1CodeReview__b.Employee__c</field>
    11. <readable>true</readable>
    12. </fieldPermissions>
    13. <fieldPermissions>
    14. <editable>true</editable>
    15. <field>Test1CodeReview__b.Story__c</field>
    16. <readable>true</readable>
    17. </fieldPermissions>
    18. <fieldPermissions>
    19. <editable>true</editable>
    20. <field>Test1CodeReview__b.CanBeMerged__c</field>
    21. <readable>true</readable>
    22. </fieldPermissions>
    23. <fieldPermissions>
    24. <editable>true</editable>
    25. <field>Test1CodeReview__b.Score__c</field>
    26. <readable>true</readable>
    27. </fieldPermissions>
    28. </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.

  1. Create a folder “objects” and move the .object file to this folder.
  2. Create a folder “permissionSets” and move the .permissionSet file to this folder.
  3. Finally create a zip file with objects folder, permissionSets folder, and package.xml file.
  4. a) Go to https://workbench.developerforce.com and login with the org credentials.
  5. b) Go to the migration and Deploy.

sfBig

Creating records for BigObject:

  1. Test1CodeReview__b tr = new Test1CodeReview__b();
  2. cr.CanBeMerged__c = ’False’;
  3. cr.CodeReviewDate__c = System.today();
  4. cr.Comments__c = ’I found a SOQL inside of a loop.’;
  5. cr.Employee__c = ’a6j24000000fxSL’;
  6. cr.Score__c = 0;
  7. cr.Story__c = ’a6k24000000k9bN’;
  8. 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

Leave a Reply

Your email address will not be published. Required fields are marked *