How to create and insert data into Big Objects

 

Use Case:

Company A stores credit card transaction data in Salesforce. Data is stored as Person Accounts all the transaction data is stored in the person account.  Number of transactions can grow to more than 10 million to 100 million depends upon the member base of the Company A

Solution:

Say for instance we are interested in

  1. Capturing transaction data under person account
  2. Processing transaction data for further processing ( like the redemption of the user acquired commissions )
  3. Letting Customer support team filter the transaction data
  4. Running reports on transaction data

 

Why can’t we use Salesforce provided Big Objects to attain above functionality.  Wait.. before we design the solution let’s understand the Big Object limitations

  1. You can’t create Big Objects using Salesforce Setup, instead use Salesforce Metadata API to create these objects
  2. No triggers can be implemented on Big Objects
  3. No Page Layouts
  4. Querying data using SOQL is comes with limitation, you can query data on Index fields
  5. You can’t design Workflows, Process Builders etc
  6. You can’t run reports on the Transaction data

Instead of looking into the negativities of the Big Objects I looked into the beauty that can bring with these limitations. I trust Salesforce Architect team designed few of these limitations on purpose due to its multi-tenant architecture. Designing triggers, querying data on non-index fields, running reports , designing workflows, process builders all have a risk when not properly handled by an architect/developer when doing things.

 

Creating Big Object 

Field NameTypeLengthIndex
Transaction DateDateIndex
Transaction AmountNumber5,2
Merchant NameText 50Index
Transaction LocationText25
CustomerIdLookup(Account)

Big Object can’t be created from Salesforce setup. In order to create Big Object you have to use Salesforce Metadata API.  Let’s create a package and deploy to Salesforce using workbench.

Create file : Customer_Transaction__B.object

 

Step #2 : Create Permission set

Customer_Transaction.permissionset

 

Step #3 : Create Package.xml file

 

Step #4 : Create zip file for deployment

Customer_Transaction__B.object,  package.xml, Customer_Transaction.permissionset

Download zip file customer_transaction

 

Step #5: use workbench to deploy the code

Upload zip file and click Next , follow the instruction to deploy the code

Step #6 : Use Bulk Api Java Code for data Migration into Big Object

 

 

Heroku postgres Integration with Force.com

Login to www.heroku.com

Go to heroku Dashboard

Click ‘New’ to create Application

Create App

Enter App name: sfdc-heroku-integration

click ‘Create app’ button to continue

 

Click on App icon and select Elements

Select Heroku Postgres on the Heroku Elements page

 

 

Click on ‘Install Heroku Postgres’ and continue

 

 

Select your app name to install Postgres

 

 

select the free version and click on Provision button

 

 

You will landup on the below page after successfully installing Postgres on the Heroku platform

 

 

Installing Heroku Connect

Heroku connect  helps you to synchronize data to Salesforce

 

 

Select app name to install Heroku Connect, in our case app name is sfdc-heroku-integration

 

 

Click on Provision button to continue

 

After successful installation, you will be landed on to the below page

 

Configuring Heroku Connect to Sync data from Salesforce

 

Click on Heroku Connect from Dashboard->App->Resources section

 

Click ‘Setup Connection’

 

Enter schema name and click Next

 

Click ‘Authorize’ and continue

 

Select your Salesforce org to install, After successful installatoin, you will see below screen

 

 

Synchronize Salesforce object data into Heroku Postgres

 

Click ‘Create Mapping’

 

select Objects you want to synchronize

 

Select Object Fields you want to Synchronize, you can also set Poll Frequency ( minimum poll frequency set at 10 minutes )

 

 

 

After you complete the setup you will see below screen. We can clearly see number of fields, number of records that are inserted into Postgres DB

Salesforce to Salesforce Integration using REST Webservice

Use Case:

An organization has two salesforce org ( Sales Org and R&D Org ). Sales Org user wants to create a support request in R&D org for a Sales Org opportunity. R&D org team has special skills to work on those Support Requests. Sales Org user is willing to share some of the opportunity field data and restrict sharing access to only for the opportunities that have Support Requests. Sales Org User is also interested to know the status and owner of the Support Request. R&D Org users should be able to run reports on Case/Support Request/Opportunity(Sales Org) data

Solution:

Providing a button on Opportunity UI to create a support request. Invoking a Visualforce page and using a controller class system can call Webservice on R&D Org to create a Case. Whenever a Support Request is created checkbox is updated in opportunity object, based on the checkbox opportunity information is shared with an integration user. Salesforce lightning connect is used to integrate Sales Org & R-&-D org. Check out my blog post on lightning connect. R&D Org can call webservice on Sales Org to update Support Request Owner and Status details in Sales Org system.

 

Implementation:

Below flow gives a top view of how the integration/data flow between the systems.

 

Step #1: Authentication

Sales Org calls Webservice on R&D Org

R&D Org authenticates Sales Org call

R&D lets Sales Org create Case after authentication

Salesforce configuration details:

Configure Connected App in R&D Org

Configure Authentical Provider in Sales Org

Configure Named Credentials in Sales Org

Use Named Credentials in Webservice Callout script

Follow blog post ‘How to configure Named Credentials

 

Step #2: Creating Webservice on R&D Org

 

 

Step #3: Controller class to create call R&D Webservice from Sales Org

 

 

Step #4: VF Page to create Support Request

 

 

Step #5 : Create Support Request button configuration on Opportunity Page

go to Setup->Opportunity->Buttons to create Button

 

 

Step : #6: Add button to Layout

 

 

 

 

 

Sample @future code – ready to process when resources are available

 

When to use?
Long-running processes or external calls
When it’s not batchable

Advantages:
Asynchronous process without concurrent limit
Easier and quicker to implement as opposed to batch

Disadvantages:
Parameters passed in can be only of primitive types
Can’t chain @future methods
Difficult to access job id

Batchable code to update Contact address with Account Address

Simple code to write Batchable code in Apex

 

 

References: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_interface_database_batchable.htm

A simple Webservice callout script

You have uncommitted work pending. Please commit or rollback before calling out

So Stuck there with “You have uncommitted work pending. Please commit or rollback before calling out”  

na!! na!! don’t say the problem I know that!! Tell me the solution?

Not every problem has one solution, Let’s go thru those multiple solutions. You are the boss, select the solution that fits your use case

Solution #1:

Do DML operations with REST API after a Callout