Thursday, 22 March 2018

Big Object in Salesforce | Difference Between Custom Object and Big Object



What is Big Object :-

Object that stores and Manages Massive data values within Salesforce Without affecting performance. Big objects provide consistent performance for a billion records, and are accessible with a standard set of API's to your org or external system.

Custom big objects can be created by the Metadata API. To define a custom big object, you need to create an object file that contains its definition, field's, and index, with a Permission-set to define the permissions for each field, and  package file to define the contents of the object metadata


What Should Consider for Big Object

1) You need to use Metadata API to create Big Object.
2) Max 100 Big objects per org
3) Support's Date Time,Lookup,Number,Text,Long Text Area Field only
4) triggers, flows, processes, and the Salesforce app are unavailable.
5) Async SOQL is included only with the licensing of additional big object capacity
6) Support only object and field permissions
7) Does not Count against org data Storage limit
8) Suffixed with "_b".


Step to Create Big Object:-

You need to create the below three files.

Step 1) Create Big Object Files:-  

1) Create an Object File :- Defines the custom big object’s fields and index, Each custom big object needs its own object file.

My_First_Big_Object__b.object


<?xml version="1.0" encoding="UTF-8"?>
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
    <deploymentStatus>Deployed</deploymentStatus>

    <fields>
        <fullName>MyTextField__c</fullName>
        <label>My Text Field</label>
        <length>16</length>
        <required>false</required>
        <type>Text</type>
        <unique>false</unique>
    </fields>
   
    <fields>
        <fullName>Account_Lookup__c</fullName>
        <label>Account Lookup</label>
        <referenceTo>Account</referenceTo>
        <relationshipName>Account_Lookup</relationshipName>
        <required>true</required>
        <type>Lookup</type>
    </fields>
   
    <fields>
        <fullName>Date_Time__c</fullName>
        <label>Date Time</label>
        <required>true</required>
        <type>DateTime</type>
    </fields>
   
    <fields>
        <fullName>Number_Field__c</fullName>
        <label>Number Field</label>
        <required>false</required>
        <type>Number</type>
        <scale>2</scale>
        <precision>16</precision>
    </fields>

    <indexes>
        <fullName>MyFirstBigIndex</fullName>
        <label>My First Big Index</label>
        <fields>
            <name>Account_Lookup__c</name>
            <sortDirection>DESC</sortDirection>
        </fields>
        <fields>
            <name>Date_Time__c</name>
            <sortDirection>DESC</sortDirection>
        </fields>
    </indexes>
   
    <label>My First Big Object</label>
    <pluralLabel>My First Big Object</pluralLabel>
   
</CustomObject>


2) Create A Permissionset file :- with a Permissionset to define the permissions for each field

My_First_Big_Object.permissionset


<?xml version="1.0" encoding="UTF-8"?>
<PermissionSet xmlns="http://soap.sforce.com/2006/04/metadata">
    
    <fieldPermissions>
        <editable>true</editable>
        <field>My_First_Big_Object__b.MyTextField__c</field>
        <readable>true</readable>
    </fieldPermissions>
        
    <fieldPermissions>
        <editable>true</editable>
        <field>My_First_Big_Object__b.Number_Field__c</field>
        <readable>true</readable>
    </fieldPermissions>
    
    <label>My_First_Big_Object Permission Set</label>
   
</PermissionSet>




3) Create package.xml file :-  file to define the contents of the object metadata

package.xml


<?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>



Step 2) Deploy big object :-

1) Create the zip file for deployment.
Save all three file in one folder. Create the folder Structure like below



Add My_First_Big_Object__b.object file in Object Folder

Add My_First_Big_Object.permissionset file in permissionset Folder

package.xml file should in root of the folder.

2) Deploy with the help of Workbench or ANT tool.

2.1) Login on workbench
2.2) Click on Migration tool in workbench and select Single Package option like below image.



2.3) Now validate the big object in your Salesforce org.



How to insert a record 



My_First_Big_Object__b obj = new My_First_Big_Object__b();
obj.Account_Lookup__c ='0019000001ukhMF';
obj.Date_Time__c=System.now();
obj.MyTextField__c='hello';
obj.Number_Field__c=10;
database.insertImmediate(obj);


Query a record


 Difference Between Custom Object and Big Object



Custom Object
Big Object
Create
Manual and Metadata
Metadata
API Name
__c
__b
Track Activity
Yes
No Option
Field History Tracking
Yes
No Option
Data Type
All
Text, Date Time, Lookup, Number, Long Text Area
Edit Field
Yes
Yes
Delete Field
Yes
No
Trigger
Yes
No
Report
Yes
No
Storage
It Count Against Storage
It doesn’t count against Storage


Recently we did the session on Big Object in Salesforce Apex Hours.

Recording :- https://www.youtube.com/watch?v=gV1Oviqzry0&t=4691s



Please check below Trailhead module for more detail
1) https://trailhead.salesforce.com/en/modules/big_objects

Thanks
Amit Chaudhary

3 comments:

  1. Except the UI and deploying XML, Can we create big objects from apex?

    ReplyDelete
    Replies
    1. Yes, you can but you need a mock to test this class. I'm trying to write de mock class :(

      Log_Integracion__b objLogIntegracion = new Log_Integracion__b();

      if(!String.isBlank(strCaseId)){
      objLogIntegracion.Case_Id__c = strCaseId;
      }

      objLogIntegracion.Fecha_Creacion__c = DateTime.now();
      objLogIntegracion.Request__c = strRequest;
      objLogIntegracion.Response__c = strResponse;
      objLogIntegracion.Tipo_Sistema__c = strTipoSistema;
      objLogIntegracion.Login_Id__c = strLoginId;
      try{
      if( !Test.isRunningTest() ){
      database.insertImmediate(objLogIntegracion);
      }
      }catch(system.exception e ){
      system.debug( 'EXCEPTION: ' + e );
      return 'Error al insertar registro: ' + e;
      }

      Delete
  2. this code is to insert a single record with 'strVariableName' like inputs

    ReplyDelete