SOQL with Big Objects. salesforce Big Objects
Anúncio
Anúncio
Big Objects SOQL with Big Objects
Re-inserting a record with the same index but different data results in behavior similar to an upsert operation. If a record with the index exists, the insert overwrites the index values with the new data. Insertion is idempotent, so inserting data that already exists won't result in duplicates. Reinserting is helpful when uploading millions of records. If an error occurs, the reinsert reuploads the failed uploads without duplicate data. During the reinsertion, if no record exists for the provided index, a new record is inserted.
Here is an example of an insert operation in Apex that assumes a table in which the index consists of
FirstName__c
,
LastName__c
, and
Address__c
.
<!-- 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);
SOQL with Big Objects
You can query the fields in a big object’s index using a subset of standard SOQL commands.
Build an index query starting from the first field defined in the index, without gaps between the first and last field in the query. You can use
=
,
<
,
>
,
<=
, or
>=
, or
IN
on the last field in your query. Any prior fields in your query can only use the
=
operator. The
!=
,
LIKE
,
NOT IN
,
EXCLUDES
, and
INCLUDES
operators are not valid in any query.
The system fields
CreatedById
,
CreatedDate
,
SystemModstamp
can be included in queries. Do not use the
Id
field in a query. Including
Id
in a query returns only results that have an empty ID (000000000000000 or 000000000000000AAA).
The following queries assume that you have a table in which the index is defined by
LastName__c
,
FirstName__c
, and
PhoneNumber__c
.
This query specifies all three fields in the index. In this case, the filter on
PhoneNumber__c
can be a range.
SELECT LastName__c, FirstName__c, PhoneNumber__c
FROM Phone_Book__b
WHERE LastName__c='Kelly' AND FirstName__c='Charlie' AND PhoneNumber__c='2155555555'
This query specifies only the first two fields in the index. In this case, the filter on
FirstName__c
can be a range.
SELECT LastName__c, FirstName__c, PhoneNumber__c
FROM Phone_Book__b
WHERE LastName__c='Kelly' AND FirstName__c='Charlie'
10
Big Objects
This query specifies only the first field in the index. The filter on
LastName__c
can be a range.
SELECT LastName__c, FirstName__c, PhoneNumber__c
FROM Phone_Book__b
WHERE LastName__c='Kelly'
This query doesn’t work because of a gap in the query where
FirstName__c
is required.
SELECT LastName__c, FirstName__c, PhoneNumber__c
FROM Phone_Book__b
WHERE LastName__c='Kelly' AND PhoneNumber__c='2155555555'
Note:
These restrictions do not apply to Async SOQL queries against big objects.
SOQL with Big Objects
11
CHAPTER 2 Async SOQL
In this chapter ...
•
•
•
Async SOQL is a method for running SOQL queries when you can’t wait for the results in real time. These queries are run in the background over Salesforce entity data, standard objects, custom objects, and big objects. It provides a convenient way to query large amounts of data stored in Salesforce.
EDITIONS
Available in: Enterprise,
Performance, Unlimited, and Developer Editions
Async SOQL is implemented as a RESTful API that enables you to run queries in the familiar syntax of SOQL. Because of its asynchronous operation, you can subset, join, and create more complex queries and not be subject to timeout limits. This situation is ideal when you have millions or billions of records and need more performant processing than is possible using synchronous SOQL. The results of each query are deposited into an object you specify, which can be a standard object, custom object, or big object.
Note: Async SOQL for standard and custom objects is in Pilot.
You can schedule multiple queries and monitor their completion status. The limit for Async SOQL queries is one concurrent query at a time.
Async SOQL Versus SOQL
SOQL and Async SOQL provide many of the same capabilities. So when would you use an Async SOQL query instead of standard 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.
Use Case: Create a working dataset with filtering
12
Async SOQL
For example, let’s say that you want to analyze the years and years of opportunity history collected by
Salesforce. The results could help you identify which current and future opportunities are more likely to close and give you a better picture of your forecast. But because the opportunity history data is stored with all the field history data across the application, the volume of data is too large to query directly.
That’s where Async SOQL comes in! You can use it to write a query that extracts a smaller, representative subset of the data that you’re interested. You can store this working dataset in a custom object and use it in reports, dashboards, or any other Force.com feature.
Use Case: Create a working dataset with coarse aggregations
13
Async SOQL
With big objects, you can now bring a much finer level of detail into your applications using data that you already have. For example, every interaction an individual has with your marketing campaign is stored as data that you can use, but it’s unwieldy in its raw form. With Async SOQL, you can aggregate that data by campaign and day, allowing you to extract the relevant details of the full dataset into a smaller, usable dataset. As in the previous example, the smaller working set can live in a custom object and be used in your reports and dashboards.
14
Download
Anúncio