Right Money Management App For Your Financial Goals
#SalesforceSaturday : Salesforce BIG Objects Explained
1. New Delhi Salesforce Developer Group
LEARN . SHARE . CELEBRATE . SALESFORCE
Big Objects Explained
2. About Me (Suraj Gupta)
● Salesforce Technical Consultant at makepositive
● More than 4 years of experience in Salesforce
Domain
● Active member of New Delhi Salesforce Developer
Group
● 161 Trailhead Badges and 4 Superbadge
LEARN . SHARE . CELEBRATE . SALESFORCE
3. About New Delhi Salesforce DG
● First Revival Meetup in February 2016
● We started with 240 Members
● We are now more than 1,250 members
● Join the Community : http://bit.ly/NewDelhiCommunity
LEARN . SHARE . CELEBRATE . SALESFORCE
4. What is SalesforceSaturday
● Started by Stephanie Herrera in Austin, Texas
● Meetup every Saturday in a Coffee Shop or
anywhere to share and learn about Salesforce
● It’s now a global phenomena with more than 25
SalesforceSaturday Group over 5 Continents
● For India, it comprises of Online Knowledge
Sharing sessions and Trailhead Challenges
LEARN . SHARE . CELEBRATE . SALESFORCE
5. What are Big Objects ?
Big objects allow you to store and
manage a massive amount of data
on the Salesforce platform.
LEARN . SHARE . CELEBRATE . SALESFORCE
1,000 100,000 1,000,000 100,000,000 1,000,000,0000
6. Types of Big Objects
BIG OBJECT
Standard Custom
Object + Permissionset + Package
LEARN . SHARE . CELEBRATE . SALESFORCE
Example:
FieldHistoryArchive
Example:
MyCustomBigObject__b
7. When you need these objects ?
● To maintain access to historical data for analysis
and other auditing purpose.
● Long term view of your users’ salesforce usages
LEARN . SHARE . CELEBRATE . SALESFORCE
8. Now what Big Objects means..
● You can create them through metadata API .
● These only supports object and permission.
● Supports SOQL
● Supports Salesforce Lightning and Classic.
● Does Not support transactions that includes big
objects, standard and custom objects
● You can’t use triggers, flows, processes, and the
Salesforce app.
● You can create up to 100 big objects per org.
LEARN . SHARE . CELEBRATE . SALESFORCE
9. How to create a custom Big Object ..
You can only create Big Object via metadata API. Once you
define and deploy, it will appear in the setup.
OBJECT
file
PERMISSIONSET
file
PACKAGE
file
LEARN . SHARE . CELEBRATE . SALESFORCE
10. Metadata for Custom Big Objects..
Custom Object
● deploymentStatus (Deployed)
● fields ( CustomField[ ] )
● fullName ( string )
● indexes ( index[] )
● label (string)
● pluralLabel (string)
Custom Field
● fullName (string)
● label (string)
● length (int)
● pluralLabel (string)
● precision (int)
● referenceTo (string)
● relationshipName (string)
● required (boolean)
● scale (int)
● type (field type)
DateTime
Lookup
Number
Text
LongTextArea
Index Field
● name
● sortDirection
LEARN . SHARE . CELEBRATE . SALESFORCE
11. Populating Big Objects
● Create a .csv file with header and use Bulk or SOAP API to
upload the data.
● Loading the data via Apex.
○ database.insertImmediate();
LEARN . SHARE . CELEBRATE . SALESFORCE
<!-- Define the record -->
<PhoneBook__b> pb = new PhoneBook__b();
pb.FirstName__c = "John";
pb.LastName__c = "Smith";
pb.Address__c = "1 Market St";
pb.PhoneNumber__c = "555-1212";
<!-- Insert the record, which creates a new record -->
database.insertImmediate(pb);
<!-- Modify a field in the index -->
pb.Address__c = "1 Market St, San Francisco, CA";
<!-- Insert the record, creating a new record because the primary key has changed -->
database.insertImmediate(pb);
<!-- Modify a field not included in the index -->
pb.PhoneNumber__c = "800-555-1212";
<!-- Insert the record, which updates the second record because the index is the same -->
database.insertImmediate(pb);
12. Querying Big Objects
● SOQL : You can query big objects using a subset of standard SOQL
commands. In this case, you don’t have to wait for the results. The queried
record returned are immediately for use in Apex.
● Async SOQL : You can also use this when you have to manage millions
and millions of records. In this case, you have to wait for the results due to
size of the data. You can schedules and runs queries asynchronously in the
background, so it can run queries that normally time out with regular SOQL.
LEARN . SHARE . CELEBRATE . SALESFORCE
13. Things to remember..
● Big Objects can be queried using SOQL and Async SOQL.
● Async SOQL uses a subset of SOQL commands.
● You don’t have to worry about queries timing out in case of Async
SOQL, because it runs in background.
● You can also use Async SOQL on Standard Objects, Custom
Objects.
● Async SOQL is implemented via Chatter REST API.
● You can use Async SOQL When You don’t need to do aggregate
queries or filtering outside of the index..
LEARN . SHARE . CELEBRATE . SALESFORCE
14. SOQL on Big Objects
● When using SOQL on Big Objects, you have to build query starting from the first
field defined in the index, without skipping any fields between the first and last
field in the query.
○ for example, You have 3 fields in your Index, then you can’t create a query
using only the first and third fields.
● You can use comparison operators =, <, >, <=, >=, or IN on the last field in your
query.
● Any prior fields in your query can only use the = operator.
● Operators Like ( !=, LIKE, NOT IN, EXCLUDES, and INCLUDES ) aren’t valid in any
query involving big objects.
LEARN . SHARE . CELEBRATE . SALESFORCE
15. Example SOQL
Assume you have a big object in which Index are defined by LastName__c,
FirstName__c and PhoneNumber__c.
SELECT LastName__c, FirstName__c, PhoneNumber__c
FROM Phone_Book__b
WHERE LastName__c='Kelly' AND FirstName__c='Charlie' AND
PhoneNumber__c='2155555555'
SELECT LastName__c, FirstName__c, PhoneNumber__c
FROM Phone_Book__b
WHERE LastName__c='Kelly' AND PhoneNumber__c='2155555555'
This query specifies all three fields in the index. In this case, the filter on PhoneNumber__c can
be a range.
This query doesn’t work because of a gap in the query where FirstName__c should be.
SELECT OldValue, NewValue
FROM FieldHistoryArchive
WHERE FieldHistoryType='Opportunity’ AND Field= ‘stage’
Standard SOQL
16. Async SOQL on Big Objects
There are two ways to use Async SOQL on Big Objects.
● Query small amount of data and put them into a custom object, so that you can
use them into your reports, dashboards, or other analytic tool.
● To create a manageable dataset is through coarse aggregations. Aggregate
functions supported by Async SOQL : AVG(field), COUNT(field), COUNT_DISTINCT(field),
SUM(field), MIN(field), MAX(field)
Forming Your Query:
There are some required fields :
● query (String)
● targetObject (String)
● targetFieldMap (Map<String, String>)
Example URL : https://yourInstance.salesforce.com/services/data/v41.0/async-queries/
LEARN . SHARE . CELEBRATE . SALESFORCE
17. Example Async SOQL
{
"query": "SELECT firstField__c, secondField__c FROM SourceObject__c",
"operation": "insert",
"targetObject": "TargetObject__c",
"targetFieldMap": {"firstField__c":"firstFieldTarget__c",
"secondField__c":"secondFieldTarget__c"
},
"targetValueMap": {"$JOB_ID":"BackgroundOperationLookup__c",
"Copy fields from source to
target":"BackgroundOperationDescription__c"
}
}
POST Request Body :
LEARN . SHARE . CELEBRATE . SALESFORCE
18. Example Async SOQL continued.
{
"jobId": "08PD000000003kiT",
"message": "",
"query": "SELECT firstField__c, secondField__c FROM SourceObject__c",
"status": "New",
"targetObject": "TargetObject__c",
"targetFieldMap": {"firstField__c":"firstFieldTarget__c",
"secondField__c":"secondFieldTarget__c"
},
"targetValueMap": {"$JOB_ID":"BackgroundOperationLookup__c",
"Copy fields from source to
target":"BackgroundOperationDescription__c"
}
}
POST Response Body :
LEARN . SHARE . CELEBRATE . SALESFORCE