Blog

Salesforce Big Objects

Who is this for:  Salesforce developers

What are Big Objects?

Big objects allow you to store and manage a massive amount (billions of rows) of data on the Salesforce platform. It provides consistent performance with massive data for searching and returning results quickly.

Big objects are accessible with a standard set of APIs to your org or external system.

Types of Big Objects:

  • Standard big objects are defined by Salesforce and are included in Salesforce products. For example FieldHistoryArchive stores the history of field changes on your Salesforce objects
  • Custom big objects are defined and deployed by you through the Metadata API.

Custom Big Objects

Considerations:

  • You must use the Metadata API to define a big object or add a field to a custom big object.
  • Big objects support custom Lightning and Visualforce components rather than standard UI elements.
  • You can create up to 100 big objects per org.
  • Features like triggers, flows, processes, and the Salesforce app are not available.
  • You can’t use Salesforce Connect external objects to access big objects in another org.

How to Create a Big Object:

Salesforce doesn’t provide the ability to define a custom big object from the Salesforce UI. The only way we have to build it is through the Metadata API. To create a big object, you need three files:

  • An object file:  This file is required to create a big object. In this file, we define the custom big object’s fields and indexes.
  • A permission set or profile file: This file is not required, but we use this file to define user access for a custom big object. Here we define field permissions for a custom big object.
  • A package.xml file: This file is also required. This is the same file which we use for salesforce component deployment and retrieval. Here we describe our custom object.

Sample big object file (Rider_History__b.object):

<?xml version="1.0" encoding="UTF-8"?>
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
   <deploymentStatus>Deployed</deploymentStatus>
       <fields>
          <fullName>Start_Location_Lat__c</fullName>
          <label>Start Location Latitude</label>
          <required>false</required>
          <type>Number</type>
          <scale>4</scale>
          <precision>7</precision>
          <unique>false</unique>
       </fields>
       <fields>
          <fullName>Start_Location_Long__c</fullName>
          <label>Start Location Longitude</label>
          <required>false</required>
          <type>Number</type>
          <scale>4</scale>
          <precision>7</precision>
          <unique>false</unique>
      </fields>
      <fields>
          <fullName>Start_Time__c</fullName>
          <label>Start Time</label>
          <required>true</required>
          <type>DateTime</type>
          <unique>false</unique>
      </fields>
      <fields>
         <fullName>End_Time__c</fullName>
         <label>End Time</label>
         <required>false</required>
         <type>DateTime</type>
         <unique>false</unique>
      </fields>
      <fields>
         <fullName>Service_Type__c</fullName>
         <label>Service Type</label>
         <length>16</length>
         <required>false</required>
         <type>Text</type>
         <unique>false</unique>
      </fields>
      <fields>
         <fullName>Rider_Account__c</fullName>
         <label>Rider Account</label>
         <length>16</length>
         <required>true</required>
         <type>Text</type>
         <unique>false</unique>
      </fields>
      <fields>
         <fullName>Rider_Rating__c</fullName>
         <label>Rider Rating</label>
         <required>false</required>
         <type>Number</type>
         <scale>1</scale>
         <precision>2</precision>
         <unique>false</unique>
      </fields>
      <indexes>
         <fullName>Rider_History_Index</fullName>
         <label>Rider History Index</label>
      <fields>
         <name>Rider_Account__c</name>
         <sortDirection>DESC</sortDirection>
      </fields>
      <fields>
         <name>Start_Time__c</name>
         <sortDirection>DESC</sortDirection>
      </fields>
 </indexes>
     <label>Rider History</label>
     <pluralLabel>Rider Histories</pluralLabel>
</CustomObject>

File location (src->objects): Rider file.jpg

Sample permission set file (rider_history.permissionset)

<?xml version="1.0" encoding="UTF-8"?>
   <PermissionSet xmlns="http://soap.sforce.com/2006/04/metadata">
      <fieldPermissions>
         <editable>true</editable>
         <field>rider_history__b.Start_Location_Lat__c</field>
         <readable>true</readable>
      </fieldPermissions>
      <fieldPermissions>
         <editable>true</editable>
         <field>rider_history__b.Start_Location_Long__c</field>
         <readable>true</readable>
      </fieldPermissions>
      <fieldPermissions>
         <editable>true</editable>
         <field>rider_history__b.End_Time__c</field>
         <readable>true</readable>
      </fieldPermissions>
      <fieldPermissions>
         <editable>true</editable>
         <field>rider_history__b.Service_Type__c</field>
         <readable>true</readable>
      </fieldPermissions>
      <fieldPermissions>
         <editable>true</editable>
         <field>rider_history__b.Rider_Rating__c</field>
         <readable>true</readable>
      </fieldPermissions>
      <label>Rider History Permission Set</label>
</PermissionSet>

File location (src->permissionsets)permissionsets.jpg

Sample package.xml file:

<?xml version="1.0" encoding="UTF-8"?>
   <Package xmlns="http://soap.sforce.com/2006/04/metadata">
   <types>
      <members>*</members>
      <name>CustomObject</name>
   </types>
   <types>
      <members>*</members>
      <name>PermissionSet</name>
   </types>
   <version>41.0</version>
</Package>

File location (src)src.jpg

 

Deployment of metadata files created above

We can use any metadata deployment tool like ant or workbench for deployment of our components.

I’ll demonstrate here using workbench:

Step 1) Zip src folder.

Step 2) Login to workbench .

Step 3) Go to migration -> Deploy

Step 4) Upload your zip folder by clicking “choose file”.

Step 5) Check options as shown below and click next.

Workbench__Deploy.jpg

 

This is what your Rider History big object looks like after deployment:

Rider History.jpg

You can see you big object under setup option “create -> big objects”

Apex CRUD operations to custom big objects

  • Create
    • public static List<Database.SaveResult> insertImmediate(List<SObject> sobjects)
    • public static Database.SaveResult insertImmediate(SObject sobject)
  • Read
    • SOQL/ Async SOQL
  • Update
    • Re-inserting a record with the same index.
  • Delete
    • public static List<Database.DeleteResult> deleteImmediate(List<SObject> sobjects)
    • public static Database.DeleteResult deleteImmediate(SObject sobject)

To query data, we have two options:

  1. Async SOQL
  2. SOQL

Use standard SOQL when:

  • You want to display the results in the UI without having the user wait for results.
  • You want results returned immediately for manipulation within a block of Apex code.
  • You know that the query will return a small amount of data.

Use Async SOQL when:

  • You are querying against millions of records.
  • You want to ensure that your query completes.
  • You do not need to do aggregate queries or filtering outside of the index.

References:

Happy coding!

SFDX Debug

Stream logs to CLI with apex:log:tail

Line Item Content

CPQ Custom Quote Lines

View File Document

Modify CPQ PDF Header and Footer

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Think we can help you? Reach out