SlideShare a Scribd company logo
1 of 48
Download to read offline
Revving Up the Force.com Formula Engine
Bud Vieira, salesforce.com, @aavra
Daisuke Kawamoto, salesforce.com, @daisukeSfdc
Nathan Shilling, Appirio, @nds9619
Safe Harbor
Safe harbor statement under the Private Securities Litigation Reform Act of 1995:
This presentation may contain forward-looking statements that involve risks, uncertainties, and assumptions. If any such uncertainties
materialize or if any of the assumptions proves incorrect, the results of salesforce.com, inc. could differ materially from the results
expressed or implied by the forward-looking statements we make. All statements other than statements of historical fact could be
deemed forward-looking, including any projections of product or service availability, subscriber growth, earnings, revenues, or other
financial items and any statements regarding strategies or plans of management for future operations, statements of belief, any
statements concerning new, planned, or upgraded services or technology developments and customer contracts or use of our services.
The risks and uncertainties referred to above include – but are not limited to – risks associated with developing and delivering new
functionality for our service, new products and services, our new business model, our past operating losses, possible fluctuations in our
operating results and rate of growth, interruptions or delays in our Web hosting, breach of our security measures, the outcome of any
litigation, risks associated with completed and any possible mergers and acquisitions, the immature market in which we operate, our
relatively limited operating history, our ability to expand, retain, and motivate our employees and manage our growth, new releases of our
service and successful customer deployment, our limited history reselling non-salesforce.com products, and utilization and selling to
larger enterprise customers. Further information on potential factors that could affect the financial results of salesforce.com, inc. is
included in our annual report on Form 10-K for the most recent fiscal year and in our quarterly report on Form 10-Q for the most recent
fiscal quarter. These documents and others containing important disclosures are available on the SEC Filings section of the Investor
Information section of our Web site.
Any unreleased services or features referenced in this or other presentations, press releases or public statements are not currently
available and may not be delivered on time or at all. Customers who purchase our services should make the purchase decisions
based upon features that are currently available. Salesforce.com, inc. assumes no obligation and does not intend to update these
forward-looking statements.
You are a Force.com developer,
architect, or administrator ...
… you want to know why your
queries & reports that use
formula fields are so slow ...
… so you can design a
solution that
scales & performs
better.
You need to understand how
formula evaluation works under
the hood!
Takeaways …
Index selective formula fields!
Reduce run-time overhead!
Why use formula fields?

Data

Logic

Display
How does a formula field work?
Filtering on formula fields
[SELECT …
FROM Invoice__c
WHERE Portfolio_Formula__c = ‘US Portfolio’
LIMIT 150]
Report

List View
To be indexed, a formula

MUST
be deterministic
How does indexing work?

Click SAVE

Save to Object

Edit Record

Evaluate
Formula

Write to
Index
Table
A field is deterministic …

… when the value of the field
DOES NOT CHANGE
between save events on its record
What prevents formula fields from being indexed?
Formula Element

Can be Indexed?

Why?

Contact__r.LastName

No

Values change between
formula record updates

< (Today() + 3)

No

Date functions change
in real time

Opportunity.Amount

No

Special functionality

Country__c

Depends

Formula field could be
non-deterministic
Fields that Force.com cannot index

Exhaustive list of fields: http://bit.ly/XL8ybp
Solution #1
Store lookup values
on the same object
Solution #1
1. Create custom field on object
2. Define workflow rules
3. Add field update actions
Or use Apex triggers
Solution #2
Split the formula
Solution #2

IF(AND((Invoice_Total__c > 1000),(Recurring__c),(Collective__c)),
IF(AND(Contact__r.Country__c="United States",(Invoice_Total__c >= 10000)), "US Over 10K",
IF(AND(Contact__r.Country__c="United States",(Invoice_Total__c >= 5000)), "US Over 5K",
IF(AND(Contact__r.Country__c="United States",(Invoice_Total__c < 5000)), "US Under 5K",
IF((Invoice_Total__c >= 8000),
IF(Contact__r.Country__c="Canada", "CAN Over 8K",
IF(Contact__r.Country__c="Italy", "IT Over 8K",
IF(Contact__r.Country__c="Australia","AU Over 8K","Other"))),
IF((Invoice_Total__c >= 4000),
IF(Contact__r.Country__c="Canada","CAN Over 4K",
IF(Contact__r.Country__c="Italy", "IT Over 4K",
IF(Contact__r.Country__c="Australia", "AU Over 4K","Other"))),
IF(Contact__r.Country__c="Italy", "IT Under 4K",
IF(Contact__r.Country__c="Canada","CAN Under 4K",
IF(Contact__r.Country__c="Australia","AU Under 4K"
,"Other”))))))) ,NULL)

Invoice Total

SELECT …
FROM Invoice__c
WHERE Formula__c = ‘US Over
8K’
SELECT …
FROM Invoice__c
WHERE Formula1__c = ‘US’
AND Formula2__c = true
AND Invoice_Total__c >= 8000

Country (lookup)

Invoice is BOTH
Recurring AND
Collective

IF(Contact__r.Country__c="United States", "US"
IF(Contact__r.Country__c="Canada", "CAN",
IF(Contact__r.Country__c="Italy", "IT",
IF(Contact__r.Country__c="Australia","AU","Other"
))),NULL)

Country (lookup)

IF( AND(Recurring__c, Collective__c ),TRUE,FALSE)

Invoice is BOTH
Recurring AND
Collective
Solution #3
Spell it out in your QUERY
Age__c = TODAY() - CloseDate
SELECT Id, Name
FROM Opportunity
WHERE Age__c > 14
AND Age__c <= 21
SELECT Id, Name
FROM Opportunity
WHERE (CloseDate > LAST_N_DAYS:14)
AND (CloseDate = LAST_N_DAYS:21)
Demo
Index selective formula fields

save thousands of ms (runTime)
Call Customer Support
Get your selective formula fields indexed
When to index formula fields

Deterministic?
Selective?
Frequently used?

INDEX
Formula complexity can

EXPLODE
run-time SQL
The formula field in this simple SOQL query …

SELECT Formula__c FROM Invoice__c
… has moderately complex logic …
IF( (Invoice_Total__c > 1000),
IF(CONTAINS(Country__c , "United States") &&(RPE__c > 500000), "US Portfolio",
IF(CONTAINS(Country__c , "United States") &&(RPE__c <= 500000), "US Non-Portfolio",
IF(CONTAINS(Country__c , "Canada") &&(RPE__c > 400000), "CAN Portfolio",
IF(CONTAINS(Country__c , "Canada") &&(RPE__c <= 400000), "CAN Non-Portfolio",
IF((RPE__c > 300000),
IF(CONTAINS(Country__c , "Italy"),"IT Portfolio",
IF(CONTAINS(Country__c , "France"),"FR Portfolio",
IF(CONTAINS(Country__c , "Australia"),"AU Portfolio",
IF(CONTAINS(Country__c , "Japan"), "JP Portfolio","Other")))),
IF(CONTAINS(Country__c , "Italy"), "IT Non-Portfolio",
IF(CONTAINS(Country__c , "France"), "FR Non-Portfolio",
IF(CONTAINS(Country__c , "Australia"), "AU Non-Portfolio",
IF(CONTAINS(Country__c , "Japan"), "JP Non-Portfolio","Other"
))))))))),NULL)
… which generates run-time SQL like this!
Where is all the SQL coming from?
• Spanning objects
• Nesting logic
• Nesting other formula fields

All at RUN TIME
Solution #1 – Store static values
• Workflow actions
• Triggers
• Integrations
Now the runtime SQL statement looks like this!

Save 100s of ms
Solution #2 – Split up the formula
IF( (Invoice_Total__c > 1000),
IF(CONTAINS(Country__c , "United States") &&(RPE__c > 500000), "US Portfolio",
IF(CONTAINS(Country__c , "United States") &&(RPE__c <= 500000), "US Non-Portfolio",
IF(CONTAINS(Country__c , "Canada") &&(RPE__c > 400000), "CAN Portfolio",
IF(CONTAINS(Country__c , "Canada") &&(RPE__c <= 400000), "CAN Non-Portfolio",
IF((RPE__c > 300000),
IF(CONTAINS(Country__c , "Italy"),"IT Portfolio",
IF(CONTAINS(Country__c , "France"),"FR Portfolio",
IF(CONTAINS(Country__c , "Australia"),"AU Portfolio",
IF(CONTAINS(Country__c , "Japan"), "JP Portfolio","Other")))),
IF(CONTAINS(Country__c , "Italy"), "IT Non-Portfolio",
IF(CONTAINS(Country__c , "France"), "FR Non-Portfolio",
IF(CONTAINS(Country__c , "Australia"), "AU Non-Portfolio",
IF(CONTAINS(Country__c , "Japan"), "JP Non-Portfolio","Other"
))))))))),NULL)

IF( (Invoice_Total__c > 1000),
IF(CONTAINS(Country__c , "United States") &&(RPE__c > 500000), "US Portfolio",
IF(CONTAINS(Country__c , "United States") &&(RPE__c <= 500000), "US Non-Portfolio",
IF(CONTAINS(Country__c , "Canada") &&(RPE__c > 400000), "CAN Portfolio",
IF(CONTAINS(Country__c , "Canada") &&(RPE__c <= 400000), "CAN Non-Portfolio",
"Other"
)))),NULL)

North America

IF( (Invoice_Total__c > 1000),
IF((RPE__c > 300000),
IF(CONTAINS(Country__c , "Italy"),"IT Portfolio",
IF(CONTAINS(Country__c , "France"),"FR Portfolio",
IF(CONTAINS(Country__c , "Australia"),"AU Portfolio",
IF(CONTAINS(Country__c , "Japan"), "JP Portfolio","Other")))),
IF(CONTAINS(Country__c , "Italy"), "IT Non-Portfolio",
IF(CONTAINS(Country__c , "France"), "FR Non-Portfolio",
IF(CONTAINS(Country__c , "Australia"), "AU Non-Portfolio",
IF(CONTAINS(Country__c , "Japan"), "JP Non-Portfolio","Other"
))))),NULL)

APAC and EMEA

Save about 100 ms
Making formulas scream!
Customer case studies
Nathan Shilling
Regional Practice Lead
Certified Technical Architect
@nds9619
All About Appirio
Appirio is a global services provider that helps enterprises
reimagine their business and become more agile using
crowdsourcing and cloud, social and mobile technology.
▪ More than 600 enterprise customers successfully moved to the cloud
▪ Strategic partner of salesforce.com since 2006
▪ On-demand access to 600,000 of the world’s top developers,
designers and data analysts through Appirio’s community
Business Challenge
• Users have multiple managers
in a hierarchy
• User Z sometimes has data
rolling up to Manager A
Details – Business Challenge
• The object we will report on is assigned to only one leaf
member of the hierarchy
• The user running the query can be a manager to multiple
members of the hierarchy
• The query should show all records at or below the Managers
top-level node
• Standard Role Hierarchy clearly doesn’t solve this!
Technical Solution – Query “My Team” records
• Formula is needed to determine “My Team” query
• “My Team” cannot be indexed
• “My Team” references Normalized data on Hierarchy record
•

If(Lead.Hierarchy__r.Parent__r.Parent__r.Level__c == User.Level__c…

•

If(Lead.Hierarchy__r.Parent__r.Level__c == User.Level__c…

• First try: Formula complexity taxed the query optimizer
• Lead object contains more than 10 million rows at any given
time
Denormalization & static values solve our problem
All the pieces put together…
• Store de-normalized hierarchy level values on Lead
• Store User’s top-level hierarchy value on User
• Simplify “My Team” formula to compare just those two sets
of fields
And the results querying from 10 million rows…
• First Iteration: 30 second query returning 1000 rows
• Using formulas to compare normalized reference fields

• Second Try: 6 second query returning 1000 rows
• Reduced formula to use de-normalized static values
• Still not fully performant because formula is not indexed

• Final Result: subsecond query returning 150 rows
• Negotiated business requirement change to only show
“Last 30 Days” of created Lead data
• A selective query using an index always wins!
Takeaways …
Index selective formula fields!
Reduce run-time overhead!
Related DevZone hands-on, mini-workshop

Wednesday
9:15AM
or
3:45PM
Bud Vieira

Daisuke Kawamoto

Nathan Shilling

Architect Evangelist
@aavra

Architect Evangelist
@daisukeSfdc

Regional Practice Lead
Certified Technical Architect
Appirio@nds9619
We want to hear
from YOU!
Please take a moment to complete our
session survey
Surveys can be found in the “My Agenda”
portion of the Dreamforce app
Hands-on Work Shop
@ Developer Zone
Wednesday 9am & 1 pm
Appendix
Formula Limits

More Related Content

Similar to Revving up the Force.com Formula Engine

Csod investor deck third quarter fina lv2
Csod investor deck third quarter   fina lv2Csod investor deck third quarter   fina lv2
Csod investor deck third quarter fina lv2ircornerstone
 
Best api features of 2016
Best api features of 2016Best api features of 2016
Best api features of 2016Peter Chittum
 
パートナーオフィスアワー (Partner Office Hour) -Monthly- ALMとDX事例
パートナーオフィスアワー (Partner Office Hour) -Monthly- ALMとDX事例パートナーオフィスアワー (Partner Office Hour) -Monthly- ALMとDX事例
パートナーオフィスアワー (Partner Office Hour) -Monthly- ALMとDX事例Takahiro Kawabata
 
If You Can Write a Salesforce Formula, You Can Use the Command Line
If You Can Write a Salesforce Formula, You Can Use the Command LineIf You Can Write a Salesforce Formula, You Can Use the Command Line
If You Can Write a Salesforce Formula, You Can Use the Command LinePeter Chittum
 
Week 1Instructions1. The purpose of this template is to gather dat.docx
Week 1Instructions1. The purpose of this template is to gather dat.docxWeek 1Instructions1. The purpose of this template is to gather dat.docx
Week 1Instructions1. The purpose of this template is to gather dat.docxlillie234567
 
If you can write a Salesforce Formula you can use the command line
If you can write a Salesforce Formula you can use the command lineIf you can write a Salesforce Formula you can use the command line
If you can write a Salesforce Formula you can use the command linePeter Chittum
 
A Whole New Platform for ISVs
A Whole New Platform for ISVsA Whole New Platform for ISVs
A Whole New Platform for ISVsTakahiro Kawabata
 
Learn More with SteveMo - Steve Molis
Learn More with SteveMo - Steve MolisLearn More with SteveMo - Steve Molis
Learn More with SteveMo - Steve MolisSalesforce Admins
 
Monitor Your Car From the Cloud: DIY Telematics and the Internet of Things
Monitor Your Car From the Cloud: DIY Telematics and the Internet of ThingsMonitor Your Car From the Cloud: DIY Telematics and the Internet of Things
Monitor Your Car From the Cloud: DIY Telematics and the Internet of ThingsSalesforce Developers
 
Formula Ninja at Dreamforce 2014
Formula Ninja at Dreamforce 2014Formula Ninja at Dreamforce 2014
Formula Ninja at Dreamforce 2014Deepa Patel
 
Welcome To The Real Time Cloud - Key Note
Welcome To The Real Time Cloud - Key NoteWelcome To The Real Time Cloud - Key Note
Welcome To The Real Time Cloud - Key NoteBLmarketing
 
Apex 10 commandments df14
Apex 10 commandments df14Apex 10 commandments df14
Apex 10 commandments df14Kevin Poorman
 
Enterprise Analytics - Salesforce.com Toronto User Group Presentation
Enterprise Analytics - Salesforce.com Toronto User Group PresentationEnterprise Analytics - Salesforce.com Toronto User Group Presentation
Enterprise Analytics - Salesforce.com Toronto User Group PresentationTorontoSFDC
 
Developing Interactive Tables and Charts in Visualforce
Developing Interactive Tables and Charts in VisualforceDeveloping Interactive Tables and Charts in Visualforce
Developing Interactive Tables and Charts in VisualforceSalesforce Developers
 
Operational Planning PowerPoint Presentation Slides
Operational Planning PowerPoint Presentation SlidesOperational Planning PowerPoint Presentation Slides
Operational Planning PowerPoint Presentation SlidesSlideTeam
 
Salesforce1 Platform ELEVATE LA workshop Dec 18, 2013
Salesforce1 Platform ELEVATE LA workshop Dec 18, 2013Salesforce1 Platform ELEVATE LA workshop Dec 18, 2013
Salesforce1 Platform ELEVATE LA workshop Dec 18, 2013Salesforce Developers
 
Strayer university acc 560
Strayer university acc 560Strayer university acc 560
Strayer university acc 560leesa marteen
 
Einstein Analytics, the art of the possible
Einstein Analytics, the art of the possibleEinstein Analytics, the art of the possible
Einstein Analytics, the art of the possiblerikkehovgaard
 
TrailheaDX Global Gathering London 2018
TrailheaDX Global Gathering London 2018TrailheaDX Global Gathering London 2018
TrailheaDX Global Gathering London 2018Keir Bowden
 

Similar to Revving up the Force.com Formula Engine (20)

Csod investor deck third quarter fina lv2
Csod investor deck third quarter   fina lv2Csod investor deck third quarter   fina lv2
Csod investor deck third quarter fina lv2
 
Best api features of 2016
Best api features of 2016Best api features of 2016
Best api features of 2016
 
パートナーオフィスアワー (Partner Office Hour) -Monthly- ALMとDX事例
パートナーオフィスアワー (Partner Office Hour) -Monthly- ALMとDX事例パートナーオフィスアワー (Partner Office Hour) -Monthly- ALMとDX事例
パートナーオフィスアワー (Partner Office Hour) -Monthly- ALMとDX事例
 
If You Can Write a Salesforce Formula, You Can Use the Command Line
If You Can Write a Salesforce Formula, You Can Use the Command LineIf You Can Write a Salesforce Formula, You Can Use the Command Line
If You Can Write a Salesforce Formula, You Can Use the Command Line
 
Week 1Instructions1. The purpose of this template is to gather dat.docx
Week 1Instructions1. The purpose of this template is to gather dat.docxWeek 1Instructions1. The purpose of this template is to gather dat.docx
Week 1Instructions1. The purpose of this template is to gather dat.docx
 
If you can write a Salesforce Formula you can use the command line
If you can write a Salesforce Formula you can use the command lineIf you can write a Salesforce Formula you can use the command line
If you can write a Salesforce Formula you can use the command line
 
A Whole New Platform for ISVs
A Whole New Platform for ISVsA Whole New Platform for ISVs
A Whole New Platform for ISVs
 
Learn More with SteveMo - Steve Molis
Learn More with SteveMo - Steve MolisLearn More with SteveMo - Steve Molis
Learn More with SteveMo - Steve Molis
 
Monitor Your Car From the Cloud: DIY Telematics and the Internet of Things
Monitor Your Car From the Cloud: DIY Telematics and the Internet of ThingsMonitor Your Car From the Cloud: DIY Telematics and the Internet of Things
Monitor Your Car From the Cloud: DIY Telematics and the Internet of Things
 
Formula Ninja at Dreamforce 2014
Formula Ninja at Dreamforce 2014Formula Ninja at Dreamforce 2014
Formula Ninja at Dreamforce 2014
 
Welcome To The Real Time Cloud - Key Note
Welcome To The Real Time Cloud - Key NoteWelcome To The Real Time Cloud - Key Note
Welcome To The Real Time Cloud - Key Note
 
Apex 10 commandments df14
Apex 10 commandments df14Apex 10 commandments df14
Apex 10 commandments df14
 
Enterprise Analytics - Salesforce.com Toronto User Group Presentation
Enterprise Analytics - Salesforce.com Toronto User Group PresentationEnterprise Analytics - Salesforce.com Toronto User Group Presentation
Enterprise Analytics - Salesforce.com Toronto User Group Presentation
 
Developing Interactive Tables and Charts in Visualforce
Developing Interactive Tables and Charts in VisualforceDeveloping Interactive Tables and Charts in Visualforce
Developing Interactive Tables and Charts in Visualforce
 
Operational Planning PowerPoint Presentation Slides
Operational Planning PowerPoint Presentation SlidesOperational Planning PowerPoint Presentation Slides
Operational Planning PowerPoint Presentation Slides
 
Salesforce1 Platform ELEVATE LA workshop Dec 18, 2013
Salesforce1 Platform ELEVATE LA workshop Dec 18, 2013Salesforce1 Platform ELEVATE LA workshop Dec 18, 2013
Salesforce1 Platform ELEVATE LA workshop Dec 18, 2013
 
Strayer university acc 560
Strayer university acc 560Strayer university acc 560
Strayer university acc 560
 
Dreamforce 2013 Investment Community Presentation
Dreamforce 2013 Investment Community PresentationDreamforce 2013 Investment Community Presentation
Dreamforce 2013 Investment Community Presentation
 
Einstein Analytics, the art of the possible
Einstein Analytics, the art of the possibleEinstein Analytics, the art of the possible
Einstein Analytics, the art of the possible
 
TrailheaDX Global Gathering London 2018
TrailheaDX Global Gathering London 2018TrailheaDX Global Gathering London 2018
TrailheaDX Global Gathering London 2018
 

More from Salesforce Developers

Sample Gallery: Reference Code and Best Practices for Salesforce Developers
Sample Gallery: Reference Code and Best Practices for Salesforce DevelopersSample Gallery: Reference Code and Best Practices for Salesforce Developers
Sample Gallery: Reference Code and Best Practices for Salesforce DevelopersSalesforce Developers
 
Maximizing Salesforce Lightning Experience and Lightning Component Performance
Maximizing Salesforce Lightning Experience and Lightning Component PerformanceMaximizing Salesforce Lightning Experience and Lightning Component Performance
Maximizing Salesforce Lightning Experience and Lightning Component PerformanceSalesforce Developers
 
Local development with Open Source Base Components
Local development with Open Source Base ComponentsLocal development with Open Source Base Components
Local development with Open Source Base ComponentsSalesforce Developers
 
TrailheaDX India : Developer Highlights
TrailheaDX India : Developer HighlightsTrailheaDX India : Developer Highlights
TrailheaDX India : Developer HighlightsSalesforce Developers
 
Why developers shouldn’t miss TrailheaDX India
Why developers shouldn’t miss TrailheaDX IndiaWhy developers shouldn’t miss TrailheaDX India
Why developers shouldn’t miss TrailheaDX IndiaSalesforce Developers
 
CodeLive: Build Lightning Web Components faster with Local Development
CodeLive: Build Lightning Web Components faster with Local DevelopmentCodeLive: Build Lightning Web Components faster with Local Development
CodeLive: Build Lightning Web Components faster with Local DevelopmentSalesforce Developers
 
CodeLive: Converting Aura Components to Lightning Web Components
CodeLive: Converting Aura Components to Lightning Web ComponentsCodeLive: Converting Aura Components to Lightning Web Components
CodeLive: Converting Aura Components to Lightning Web ComponentsSalesforce Developers
 
Enterprise-grade UI with open source Lightning Web Components
Enterprise-grade UI with open source Lightning Web ComponentsEnterprise-grade UI with open source Lightning Web Components
Enterprise-grade UI with open source Lightning Web ComponentsSalesforce Developers
 
TrailheaDX and Summer '19: Developer Highlights
TrailheaDX and Summer '19: Developer HighlightsTrailheaDX and Summer '19: Developer Highlights
TrailheaDX and Summer '19: Developer HighlightsSalesforce Developers
 
Lightning web components - Episode 4 : Security and Testing
Lightning web components  - Episode 4 : Security and TestingLightning web components  - Episode 4 : Security and Testing
Lightning web components - Episode 4 : Security and TestingSalesforce Developers
 
LWC Episode 3- Component Communication and Aura Interoperability
LWC Episode 3- Component Communication and Aura InteroperabilityLWC Episode 3- Component Communication and Aura Interoperability
LWC Episode 3- Component Communication and Aura InteroperabilitySalesforce Developers
 
Lightning web components episode 2- work with salesforce data
Lightning web components   episode 2- work with salesforce dataLightning web components   episode 2- work with salesforce data
Lightning web components episode 2- work with salesforce dataSalesforce Developers
 
Lightning web components - Episode 1 - An Introduction
Lightning web components - Episode 1 - An IntroductionLightning web components - Episode 1 - An Introduction
Lightning web components - Episode 1 - An IntroductionSalesforce Developers
 
Migrating CPQ to Advanced Calculator and JSQCP
Migrating CPQ to Advanced Calculator and JSQCPMigrating CPQ to Advanced Calculator and JSQCP
Migrating CPQ to Advanced Calculator and JSQCPSalesforce Developers
 
Scale with Large Data Volumes and Big Objects in Salesforce
Scale with Large Data Volumes and Big Objects in SalesforceScale with Large Data Volumes and Big Objects in Salesforce
Scale with Large Data Volumes and Big Objects in SalesforceSalesforce Developers
 
Replicate Salesforce Data in Real Time with Change Data Capture
Replicate Salesforce Data in Real Time with Change Data CaptureReplicate Salesforce Data in Real Time with Change Data Capture
Replicate Salesforce Data in Real Time with Change Data CaptureSalesforce Developers
 
Modern Development with Salesforce DX
Modern Development with Salesforce DXModern Development with Salesforce DX
Modern Development with Salesforce DXSalesforce Developers
 
Integrate CMS Content Into Lightning Communities with CMS Connect
Integrate CMS Content Into Lightning Communities with CMS ConnectIntegrate CMS Content Into Lightning Communities with CMS Connect
Integrate CMS Content Into Lightning Communities with CMS ConnectSalesforce Developers
 

More from Salesforce Developers (20)

Sample Gallery: Reference Code and Best Practices for Salesforce Developers
Sample Gallery: Reference Code and Best Practices for Salesforce DevelopersSample Gallery: Reference Code and Best Practices for Salesforce Developers
Sample Gallery: Reference Code and Best Practices for Salesforce Developers
 
Maximizing Salesforce Lightning Experience and Lightning Component Performance
Maximizing Salesforce Lightning Experience and Lightning Component PerformanceMaximizing Salesforce Lightning Experience and Lightning Component Performance
Maximizing Salesforce Lightning Experience and Lightning Component Performance
 
Local development with Open Source Base Components
Local development with Open Source Base ComponentsLocal development with Open Source Base Components
Local development with Open Source Base Components
 
TrailheaDX India : Developer Highlights
TrailheaDX India : Developer HighlightsTrailheaDX India : Developer Highlights
TrailheaDX India : Developer Highlights
 
Why developers shouldn’t miss TrailheaDX India
Why developers shouldn’t miss TrailheaDX IndiaWhy developers shouldn’t miss TrailheaDX India
Why developers shouldn’t miss TrailheaDX India
 
CodeLive: Build Lightning Web Components faster with Local Development
CodeLive: Build Lightning Web Components faster with Local DevelopmentCodeLive: Build Lightning Web Components faster with Local Development
CodeLive: Build Lightning Web Components faster with Local Development
 
CodeLive: Converting Aura Components to Lightning Web Components
CodeLive: Converting Aura Components to Lightning Web ComponentsCodeLive: Converting Aura Components to Lightning Web Components
CodeLive: Converting Aura Components to Lightning Web Components
 
Enterprise-grade UI with open source Lightning Web Components
Enterprise-grade UI with open source Lightning Web ComponentsEnterprise-grade UI with open source Lightning Web Components
Enterprise-grade UI with open source Lightning Web Components
 
TrailheaDX and Summer '19: Developer Highlights
TrailheaDX and Summer '19: Developer HighlightsTrailheaDX and Summer '19: Developer Highlights
TrailheaDX and Summer '19: Developer Highlights
 
Live coding with LWC
Live coding with LWCLive coding with LWC
Live coding with LWC
 
Lightning web components - Episode 4 : Security and Testing
Lightning web components  - Episode 4 : Security and TestingLightning web components  - Episode 4 : Security and Testing
Lightning web components - Episode 4 : Security and Testing
 
LWC Episode 3- Component Communication and Aura Interoperability
LWC Episode 3- Component Communication and Aura InteroperabilityLWC Episode 3- Component Communication and Aura Interoperability
LWC Episode 3- Component Communication and Aura Interoperability
 
Lightning web components episode 2- work with salesforce data
Lightning web components   episode 2- work with salesforce dataLightning web components   episode 2- work with salesforce data
Lightning web components episode 2- work with salesforce data
 
Lightning web components - Episode 1 - An Introduction
Lightning web components - Episode 1 - An IntroductionLightning web components - Episode 1 - An Introduction
Lightning web components - Episode 1 - An Introduction
 
Migrating CPQ to Advanced Calculator and JSQCP
Migrating CPQ to Advanced Calculator and JSQCPMigrating CPQ to Advanced Calculator and JSQCP
Migrating CPQ to Advanced Calculator and JSQCP
 
Scale with Large Data Volumes and Big Objects in Salesforce
Scale with Large Data Volumes and Big Objects in SalesforceScale with Large Data Volumes and Big Objects in Salesforce
Scale with Large Data Volumes and Big Objects in Salesforce
 
Replicate Salesforce Data in Real Time with Change Data Capture
Replicate Salesforce Data in Real Time with Change Data CaptureReplicate Salesforce Data in Real Time with Change Data Capture
Replicate Salesforce Data in Real Time with Change Data Capture
 
Modern Development with Salesforce DX
Modern Development with Salesforce DXModern Development with Salesforce DX
Modern Development with Salesforce DX
 
Get Into Lightning Flow Development
Get Into Lightning Flow DevelopmentGet Into Lightning Flow Development
Get Into Lightning Flow Development
 
Integrate CMS Content Into Lightning Communities with CMS Connect
Integrate CMS Content Into Lightning Communities with CMS ConnectIntegrate CMS Content Into Lightning Communities with CMS Connect
Integrate CMS Content Into Lightning Communities with CMS Connect
 

Recently uploaded

Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfjimielynbastida
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfngoud9212
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsAndrey Dotsenko
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsPrecisely
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdf
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdf
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power Systems
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 

Revving up the Force.com Formula Engine

  • 1. Revving Up the Force.com Formula Engine Bud Vieira, salesforce.com, @aavra Daisuke Kawamoto, salesforce.com, @daisukeSfdc Nathan Shilling, Appirio, @nds9619
  • 2. Safe Harbor Safe harbor statement under the Private Securities Litigation Reform Act of 1995: This presentation may contain forward-looking statements that involve risks, uncertainties, and assumptions. If any such uncertainties materialize or if any of the assumptions proves incorrect, the results of salesforce.com, inc. could differ materially from the results expressed or implied by the forward-looking statements we make. All statements other than statements of historical fact could be deemed forward-looking, including any projections of product or service availability, subscriber growth, earnings, revenues, or other financial items and any statements regarding strategies or plans of management for future operations, statements of belief, any statements concerning new, planned, or upgraded services or technology developments and customer contracts or use of our services. The risks and uncertainties referred to above include – but are not limited to – risks associated with developing and delivering new functionality for our service, new products and services, our new business model, our past operating losses, possible fluctuations in our operating results and rate of growth, interruptions or delays in our Web hosting, breach of our security measures, the outcome of any litigation, risks associated with completed and any possible mergers and acquisitions, the immature market in which we operate, our relatively limited operating history, our ability to expand, retain, and motivate our employees and manage our growth, new releases of our service and successful customer deployment, our limited history reselling non-salesforce.com products, and utilization and selling to larger enterprise customers. Further information on potential factors that could affect the financial results of salesforce.com, inc. is included in our annual report on Form 10-K for the most recent fiscal year and in our quarterly report on Form 10-Q for the most recent fiscal quarter. These documents and others containing important disclosures are available on the SEC Filings section of the Investor Information section of our Web site. Any unreleased services or features referenced in this or other presentations, press releases or public statements are not currently available and may not be delivered on time or at all. Customers who purchase our services should make the purchase decisions based upon features that are currently available. Salesforce.com, inc. assumes no obligation and does not intend to update these forward-looking statements.
  • 3. You are a Force.com developer, architect, or administrator ...
  • 4. … you want to know why your queries & reports that use formula fields are so slow ...
  • 5. … so you can design a solution that scales & performs better.
  • 6. You need to understand how formula evaluation works under the hood!
  • 7. Takeaways … Index selective formula fields! Reduce run-time overhead!
  • 8. Why use formula fields? Data Logic Display
  • 9. How does a formula field work?
  • 10. Filtering on formula fields [SELECT … FROM Invoice__c WHERE Portfolio_Formula__c = ‘US Portfolio’ LIMIT 150] Report List View
  • 11. To be indexed, a formula MUST be deterministic
  • 12. How does indexing work? Click SAVE Save to Object Edit Record Evaluate Formula Write to Index Table
  • 13. A field is deterministic … … when the value of the field DOES NOT CHANGE between save events on its record
  • 14. What prevents formula fields from being indexed? Formula Element Can be Indexed? Why? Contact__r.LastName No Values change between formula record updates < (Today() + 3) No Date functions change in real time Opportunity.Amount No Special functionality Country__c Depends Formula field could be non-deterministic
  • 15. Fields that Force.com cannot index Exhaustive list of fields: http://bit.ly/XL8ybp
  • 16. Solution #1 Store lookup values on the same object
  • 17. Solution #1 1. Create custom field on object 2. Define workflow rules 3. Add field update actions Or use Apex triggers
  • 19. Solution #2 IF(AND((Invoice_Total__c > 1000),(Recurring__c),(Collective__c)), IF(AND(Contact__r.Country__c="United States",(Invoice_Total__c >= 10000)), "US Over 10K", IF(AND(Contact__r.Country__c="United States",(Invoice_Total__c >= 5000)), "US Over 5K", IF(AND(Contact__r.Country__c="United States",(Invoice_Total__c < 5000)), "US Under 5K", IF((Invoice_Total__c >= 8000), IF(Contact__r.Country__c="Canada", "CAN Over 8K", IF(Contact__r.Country__c="Italy", "IT Over 8K", IF(Contact__r.Country__c="Australia","AU Over 8K","Other"))), IF((Invoice_Total__c >= 4000), IF(Contact__r.Country__c="Canada","CAN Over 4K", IF(Contact__r.Country__c="Italy", "IT Over 4K", IF(Contact__r.Country__c="Australia", "AU Over 4K","Other"))), IF(Contact__r.Country__c="Italy", "IT Under 4K", IF(Contact__r.Country__c="Canada","CAN Under 4K", IF(Contact__r.Country__c="Australia","AU Under 4K" ,"Other”))))))) ,NULL) Invoice Total SELECT … FROM Invoice__c WHERE Formula__c = ‘US Over 8K’ SELECT … FROM Invoice__c WHERE Formula1__c = ‘US’ AND Formula2__c = true AND Invoice_Total__c >= 8000 Country (lookup) Invoice is BOTH Recurring AND Collective IF(Contact__r.Country__c="United States", "US" IF(Contact__r.Country__c="Canada", "CAN", IF(Contact__r.Country__c="Italy", "IT", IF(Contact__r.Country__c="Australia","AU","Other" ))),NULL) Country (lookup) IF( AND(Recurring__c, Collective__c ),TRUE,FALSE) Invoice is BOTH Recurring AND Collective
  • 20. Solution #3 Spell it out in your QUERY Age__c = TODAY() - CloseDate SELECT Id, Name FROM Opportunity WHERE Age__c > 14 AND Age__c <= 21 SELECT Id, Name FROM Opportunity WHERE (CloseDate > LAST_N_DAYS:14) AND (CloseDate = LAST_N_DAYS:21)
  • 21. Demo
  • 22. Index selective formula fields save thousands of ms (runTime) Call Customer Support Get your selective formula fields indexed
  • 23. When to index formula fields Deterministic? Selective? Frequently used? INDEX
  • 25. The formula field in this simple SOQL query … SELECT Formula__c FROM Invoice__c
  • 26. … has moderately complex logic … IF( (Invoice_Total__c > 1000), IF(CONTAINS(Country__c , "United States") &&(RPE__c > 500000), "US Portfolio", IF(CONTAINS(Country__c , "United States") &&(RPE__c <= 500000), "US Non-Portfolio", IF(CONTAINS(Country__c , "Canada") &&(RPE__c > 400000), "CAN Portfolio", IF(CONTAINS(Country__c , "Canada") &&(RPE__c <= 400000), "CAN Non-Portfolio", IF((RPE__c > 300000), IF(CONTAINS(Country__c , "Italy"),"IT Portfolio", IF(CONTAINS(Country__c , "France"),"FR Portfolio", IF(CONTAINS(Country__c , "Australia"),"AU Portfolio", IF(CONTAINS(Country__c , "Japan"), "JP Portfolio","Other")))), IF(CONTAINS(Country__c , "Italy"), "IT Non-Portfolio", IF(CONTAINS(Country__c , "France"), "FR Non-Portfolio", IF(CONTAINS(Country__c , "Australia"), "AU Non-Portfolio", IF(CONTAINS(Country__c , "Japan"), "JP Non-Portfolio","Other" ))))))))),NULL)
  • 27. … which generates run-time SQL like this!
  • 28. Where is all the SQL coming from? • Spanning objects • Nesting logic • Nesting other formula fields All at RUN TIME
  • 29. Solution #1 – Store static values • Workflow actions • Triggers • Integrations
  • 30. Now the runtime SQL statement looks like this! Save 100s of ms
  • 31. Solution #2 – Split up the formula IF( (Invoice_Total__c > 1000), IF(CONTAINS(Country__c , "United States") &&(RPE__c > 500000), "US Portfolio", IF(CONTAINS(Country__c , "United States") &&(RPE__c <= 500000), "US Non-Portfolio", IF(CONTAINS(Country__c , "Canada") &&(RPE__c > 400000), "CAN Portfolio", IF(CONTAINS(Country__c , "Canada") &&(RPE__c <= 400000), "CAN Non-Portfolio", IF((RPE__c > 300000), IF(CONTAINS(Country__c , "Italy"),"IT Portfolio", IF(CONTAINS(Country__c , "France"),"FR Portfolio", IF(CONTAINS(Country__c , "Australia"),"AU Portfolio", IF(CONTAINS(Country__c , "Japan"), "JP Portfolio","Other")))), IF(CONTAINS(Country__c , "Italy"), "IT Non-Portfolio", IF(CONTAINS(Country__c , "France"), "FR Non-Portfolio", IF(CONTAINS(Country__c , "Australia"), "AU Non-Portfolio", IF(CONTAINS(Country__c , "Japan"), "JP Non-Portfolio","Other" ))))))))),NULL) IF( (Invoice_Total__c > 1000), IF(CONTAINS(Country__c , "United States") &&(RPE__c > 500000), "US Portfolio", IF(CONTAINS(Country__c , "United States") &&(RPE__c <= 500000), "US Non-Portfolio", IF(CONTAINS(Country__c , "Canada") &&(RPE__c > 400000), "CAN Portfolio", IF(CONTAINS(Country__c , "Canada") &&(RPE__c <= 400000), "CAN Non-Portfolio", "Other" )))),NULL) North America IF( (Invoice_Total__c > 1000), IF((RPE__c > 300000), IF(CONTAINS(Country__c , "Italy"),"IT Portfolio", IF(CONTAINS(Country__c , "France"),"FR Portfolio", IF(CONTAINS(Country__c , "Australia"),"AU Portfolio", IF(CONTAINS(Country__c , "Japan"), "JP Portfolio","Other")))), IF(CONTAINS(Country__c , "Italy"), "IT Non-Portfolio", IF(CONTAINS(Country__c , "France"), "FR Non-Portfolio", IF(CONTAINS(Country__c , "Australia"), "AU Non-Portfolio", IF(CONTAINS(Country__c , "Japan"), "JP Non-Portfolio","Other" ))))),NULL) APAC and EMEA Save about 100 ms
  • 33. Nathan Shilling Regional Practice Lead Certified Technical Architect @nds9619
  • 34. All About Appirio Appirio is a global services provider that helps enterprises reimagine their business and become more agile using crowdsourcing and cloud, social and mobile technology. ▪ More than 600 enterprise customers successfully moved to the cloud ▪ Strategic partner of salesforce.com since 2006 ▪ On-demand access to 600,000 of the world’s top developers, designers and data analysts through Appirio’s community
  • 35. Business Challenge • Users have multiple managers in a hierarchy • User Z sometimes has data rolling up to Manager A
  • 36. Details – Business Challenge • The object we will report on is assigned to only one leaf member of the hierarchy • The user running the query can be a manager to multiple members of the hierarchy • The query should show all records at or below the Managers top-level node • Standard Role Hierarchy clearly doesn’t solve this!
  • 37. Technical Solution – Query “My Team” records • Formula is needed to determine “My Team” query • “My Team” cannot be indexed • “My Team” references Normalized data on Hierarchy record • If(Lead.Hierarchy__r.Parent__r.Parent__r.Level__c == User.Level__c… • If(Lead.Hierarchy__r.Parent__r.Level__c == User.Level__c… • First try: Formula complexity taxed the query optimizer • Lead object contains more than 10 million rows at any given time
  • 38. Denormalization & static values solve our problem
  • 39. All the pieces put together… • Store de-normalized hierarchy level values on Lead • Store User’s top-level hierarchy value on User • Simplify “My Team” formula to compare just those two sets of fields
  • 40. And the results querying from 10 million rows… • First Iteration: 30 second query returning 1000 rows • Using formulas to compare normalized reference fields • Second Try: 6 second query returning 1000 rows • Reduced formula to use de-normalized static values • Still not fully performant because formula is not indexed • Final Result: subsecond query returning 150 rows • Negotiated business requirement change to only show “Last 30 Days” of created Lead data • A selective query using an index always wins!
  • 41. Takeaways … Index selective formula fields! Reduce run-time overhead!
  • 42. Related DevZone hands-on, mini-workshop Wednesday 9:15AM or 3:45PM
  • 43. Bud Vieira Daisuke Kawamoto Nathan Shilling Architect Evangelist @aavra Architect Evangelist @daisukeSfdc Regional Practice Lead Certified Technical Architect Appirio@nds9619
  • 44. We want to hear from YOU! Please take a moment to complete our session survey Surveys can be found in the “My Agenda” portion of the Dreamforce app
  • 45.
  • 46. Hands-on Work Shop @ Developer Zone Wednesday 9am & 1 pm