SlideShare ist ein Scribd-Unternehmen logo
1 von 19
Downloaden Sie, um offline zu lesen
High reliability DML and concurrency
design patterns for Apex
Dan Appleman, Full Circle CRM, CTO
Author: Advanced Apex Programming for Salesforce.com and Force.com
@danappleman
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.
Have you ever seen…
EXCEPTION_THROWN [32]|System.QueryException: Record Currently
Unavailable: The record you are attempting to edit, or one of its related
records, is currently being modified by another user. Please try again.

Or
FATAL_ERROR System.DmlException: Update failed. First exception on
row 0 with id ……………; first error: UNABLE_TO_LOCK_ROW, unable
to obtain exclusive access to this record: []
Concurrency Problems
The most dangerous kind of bug in all of computer science.
Why? Because concurrency problems and bugs can be:
▪Virtually impossible to detect
▪Virtually impossible to reproduce
Most of us learn about concurrency errors as
children…
Dad, can we go to
the party?
Let me think: NO!
Most of us learn about concurrency errors as
children…
Dad, can we go to
the party?
Let me think: NO!

15 seconds later
Mom can we go to
the party?
Sure, why not?
… or as parents
Dad, can we go to
the party?
Let me check with
your mom
Pessimistic locking

Mom can we go to
the party?
What did your dad say?
Optimistic locking
…or in Salesforce
Two Salespeople receive simultaneous instructions from two
different contacts on an opportunity…

This would be very bad
…or in Salesforce
Two Salespeople receive simultaneous instructions from two
different contacts on an opportunity…

Salesforce detects the
other users’ modification
Optimistic locking (so to speak)

APEX DOES NOT DO THIS!
…or in Salesforce
Two Salespeople receive simultaneous instructions from two
different contacts on an opportunity…

SOQL “For Update” Query
Pessimistic locking

Block another thread > 10 seconds =
UNABLE_TO_LOCK_ROW error
Common Lock Conditions
▪ Data skew
▪ Insert or owner change can lock a parent during sharing calculations

▪ After a record update
▪ Records have to be locked to allow rollback in case of an exception

▪ “For Update” query
▪ Explicit lock
Common Lock Solutions
▪ Data skew
▪ Reassign record ownership

▪ After a record update
▪ Defer record updates to the end of the execution context

▪ “For Update” query
▪ Avoid or delay where possible

▪ You cannot absolutely prevent these errors
▪ More common on high traffic systems with lots of code
Reproducing Lock Errors
▪ Use future calls and anonymous Apex
▪ You can simulate them in unit tests
Handling Lock Errors
▪ In triggers and VisualForce
▪ Let the user deal with them

▪ In asynchronous code
▪ Logging
▪ Recovery
For More Information
Advanced Apex Programming for Salesforce.com and Force.com –
Second Edition
•
•
•
•
•

Incorporates changes through Winter 14
Designing for CPU Time limits
Extended chapter on triggers
Extended chapter on asynchronous patterns
New chapter on concurrency patterns
All About Full Circle CRM
Full Circle CRM develops native Salesforce.com applications
that enable marketers to accurately track and measure
marketing campaign performance directly in Salesforce
▪ Bridge the information gap between leads and contacts
▪ Obtain complete and detailed campaign performance metrics
▪ Develop advanced campaign attribution and influence analytics

Booth 1324 Moscone North
Download sample code for this session at
www.AdvancedApex.com/Dreamforce13
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
High Reliability DML and Concurrency Design Patterns for Apex

Weitere ähnliche Inhalte

Was ist angesagt?

Salesforce Cross-Cloud Architecture
Salesforce Cross-Cloud ArchitectureSalesforce Cross-Cloud Architecture
Salesforce Cross-Cloud ArchitectureThierry TROUIN ☁
 
AWS Serverless Interface Building and Cerner's FHIR Experience (HLC401) - AWS...
AWS Serverless Interface Building and Cerner's FHIR Experience (HLC401) - AWS...AWS Serverless Interface Building and Cerner's FHIR Experience (HLC401) - AWS...
AWS Serverless Interface Building and Cerner's FHIR Experience (HLC401) - AWS...Amazon Web Services
 
Oracle financials functional training on ap, ar & gl
Oracle financials functional training on ap, ar & glOracle financials functional training on ap, ar & gl
Oracle financials functional training on ap, ar & glmagnifics
 
Salesforce Development Best Practices
Salesforce Development Best PracticesSalesforce Development Best Practices
Salesforce Development Best PracticesVivek Chawla
 
How to Rock a Salesforce Demo (and why it matters)
How to Rock a Salesforce Demo (and why it matters)How to Rock a Salesforce Demo (and why it matters)
How to Rock a Salesforce Demo (and why it matters)Salesforce Admins
 
How to Rock Your Next Presentation and Demo
How to Rock Your Next Presentation and Demo How to Rock Your Next Presentation and Demo
How to Rock Your Next Presentation and Demo Salesforce Admins
 
Oracle Fusion Applications Navigation and Roles
Oracle Fusion Applications Navigation and RolesOracle Fusion Applications Navigation and Roles
Oracle Fusion Applications Navigation and RolesEmiconhrd
 
Salesforce Integration with MuleSoft | MuleSoft Mysore Meetup #12
Salesforce Integration with MuleSoft | MuleSoft Mysore Meetup #12Salesforce Integration with MuleSoft | MuleSoft Mysore Meetup #12
Salesforce Integration with MuleSoft | MuleSoft Mysore Meetup #12MysoreMuleSoftMeetup
 
DevOps Center_ArchitectGroup
DevOps Center_ArchitectGroup DevOps Center_ArchitectGroup
DevOps Center_ArchitectGroup AmeyKulkarni84
 
Decluttering your Salesfroce org
Decluttering your Salesfroce orgDecluttering your Salesfroce org
Decluttering your Salesfroce orgRoy Gilad
 
Introduction to the Salesforce Security Model
Introduction to the Salesforce Security ModelIntroduction to the Salesforce Security Model
Introduction to the Salesforce Security ModelSalesforce Developers
 
Security and Your Salesforce Org
Security and Your Salesforce OrgSecurity and Your Salesforce Org
Security and Your Salesforce OrgSalesforce Admins
 
Salesforce integration best practices columbus meetup
Salesforce integration best practices   columbus meetupSalesforce integration best practices   columbus meetup
Salesforce integration best practices columbus meetupMuleSoft Meetup
 
Oracle EPM Cloud for Midsize Customers
Oracle EPM Cloud for Midsize CustomersOracle EPM Cloud for Midsize Customers
Oracle EPM Cloud for Midsize CustomersAlithya
 
Apex Trigger Debugging: Solving the Hard Problems
Apex Trigger Debugging: Solving the Hard ProblemsApex Trigger Debugging: Solving the Hard Problems
Apex Trigger Debugging: Solving the Hard ProblemsSalesforce Developers
 

Was ist angesagt? (20)

Salesforce Cross-Cloud Architecture
Salesforce Cross-Cloud ArchitectureSalesforce Cross-Cloud Architecture
Salesforce Cross-Cloud Architecture
 
AWS Serverless Interface Building and Cerner's FHIR Experience (HLC401) - AWS...
AWS Serverless Interface Building and Cerner's FHIR Experience (HLC401) - AWS...AWS Serverless Interface Building and Cerner's FHIR Experience (HLC401) - AWS...
AWS Serverless Interface Building and Cerner's FHIR Experience (HLC401) - AWS...
 
Oracle financials functional training on ap, ar & gl
Oracle financials functional training on ap, ar & glOracle financials functional training on ap, ar & gl
Oracle financials functional training on ap, ar & gl
 
Salesforce Development Best Practices
Salesforce Development Best PracticesSalesforce Development Best Practices
Salesforce Development Best Practices
 
How to Rock a Salesforce Demo (and why it matters)
How to Rock a Salesforce Demo (and why it matters)How to Rock a Salesforce Demo (and why it matters)
How to Rock a Salesforce Demo (and why it matters)
 
How to Rock Your Next Presentation and Demo
How to Rock Your Next Presentation and Demo How to Rock Your Next Presentation and Demo
How to Rock Your Next Presentation and Demo
 
Oracle Fusion Applications Navigation and Roles
Oracle Fusion Applications Navigation and RolesOracle Fusion Applications Navigation and Roles
Oracle Fusion Applications Navigation and Roles
 
Architect day 20181128 - Afternoon Session
Architect day 20181128 - Afternoon SessionArchitect day 20181128 - Afternoon Session
Architect day 20181128 - Afternoon Session
 
Salesforce Integration with MuleSoft | MuleSoft Mysore Meetup #12
Salesforce Integration with MuleSoft | MuleSoft Mysore Meetup #12Salesforce Integration with MuleSoft | MuleSoft Mysore Meetup #12
Salesforce Integration with MuleSoft | MuleSoft Mysore Meetup #12
 
DevOps Center_ArchitectGroup
DevOps Center_ArchitectGroup DevOps Center_ArchitectGroup
DevOps Center_ArchitectGroup
 
Data model in salesforce
Data model in salesforceData model in salesforce
Data model in salesforce
 
Decluttering your Salesfroce org
Decluttering your Salesfroce orgDecluttering your Salesfroce org
Decluttering your Salesfroce org
 
Introduction to Apex Triggers
Introduction to Apex TriggersIntroduction to Apex Triggers
Introduction to Apex Triggers
 
Introduction to the Salesforce Security Model
Introduction to the Salesforce Security ModelIntroduction to the Salesforce Security Model
Introduction to the Salesforce Security Model
 
Security and Your Salesforce Org
Security and Your Salesforce OrgSecurity and Your Salesforce Org
Security and Your Salesforce Org
 
Salesforce integration best practices columbus meetup
Salesforce integration best practices   columbus meetupSalesforce integration best practices   columbus meetup
Salesforce integration best practices columbus meetup
 
Oracle EPM Cloud for Midsize Customers
Oracle EPM Cloud for Midsize CustomersOracle EPM Cloud for Midsize Customers
Oracle EPM Cloud for Midsize Customers
 
SAP PPM 5.0 Trainings
SAP PPM 5.0 TrainingsSAP PPM 5.0 Trainings
SAP PPM 5.0 Trainings
 
Large Data Management Strategies
Large Data Management StrategiesLarge Data Management Strategies
Large Data Management Strategies
 
Apex Trigger Debugging: Solving the Hard Problems
Apex Trigger Debugging: Solving the Hard ProblemsApex Trigger Debugging: Solving the Hard Problems
Apex Trigger Debugging: Solving the Hard Problems
 

Ähnlich wie High Reliability DML and Concurrency Design Patterns for Apex

CodeLive with Cynthia Thomas - Refactoring data dependent code.
CodeLive with Cynthia Thomas - Refactoring data dependent code.CodeLive with Cynthia Thomas - Refactoring data dependent code.
CodeLive with Cynthia Thomas - Refactoring data dependent code.JackGuo20
 
Salesforce Tour Breakout Session: New Features for Salesforce Admins
Salesforce Tour Breakout Session:  New Features for Salesforce AdminsSalesforce Tour Breakout Session:  New Features for Salesforce Admins
Salesforce Tour Breakout Session: New Features for Salesforce AdminsSalesforce Admins
 
Getting Started with Salesforce for Non-Profits by Nik Panter
Getting Started with Salesforce for Non-Profits by Nik PanterGetting Started with Salesforce for Non-Profits by Nik Panter
Getting Started with Salesforce for Non-Profits by Nik PanterSalesforce Admins
 
CodeLive with Adam Daw - Building a mobile friendly geolocation aware candy t...
CodeLive with Adam Daw - Building a mobile friendly geolocation aware candy t...CodeLive with Adam Daw - Building a mobile friendly geolocation aware candy t...
CodeLive with Adam Daw - Building a mobile friendly geolocation aware candy t...JackGuo20
 
Developing on the Salesforce Platform With Clicks, Not Code
Developing on the Salesforce Platform With Clicks, Not CodeDeveloping on the Salesforce Platform With Clicks, Not Code
Developing on the Salesforce Platform With Clicks, Not CodeSalesforce Developers
 
Dreamforce 2014 - Salesforce Python SDK for REST/SOAP APIs
Dreamforce 2014 - Salesforce Python SDK for REST/SOAP APIsDreamforce 2014 - Salesforce Python SDK for REST/SOAP APIs
Dreamforce 2014 - Salesforce Python SDK for REST/SOAP APIsHormoz Tarevern
 
Five Developer Tips Every Admin Needs To Know
Five Developer Tips Every Admin Needs To KnowFive Developer Tips Every Admin Needs To Know
Five Developer Tips Every Admin Needs To KnowSalesforce Developers
 
Getting Starting with Salesforce for Nonprofits
Getting Starting with Salesforce for NonprofitsGetting Starting with Salesforce for Nonprofits
Getting Starting with Salesforce for NonprofitsNik Panter
 
Top Pipeline Management Reports
Top Pipeline Management ReportsTop Pipeline Management Reports
Top Pipeline Management ReportsDreamforce
 
The ABCs of Salesforce - Rachel Natik
The ABCs of Salesforce - Rachel NatikThe ABCs of Salesforce - Rachel Natik
The ABCs of Salesforce - Rachel NatikSalesforce Admins
 
Winter '15 Highlights for Salesforce Admins
Winter '15 Highlights for Salesforce AdminsWinter '15 Highlights for Salesforce Admins
Winter '15 Highlights for Salesforce AdminsSalesforce Admins
 
Supercharge your License Management - Salesforce AppExchange
Supercharge your License Management - Salesforce AppExchangeSupercharge your License Management - Salesforce AppExchange
Supercharge your License Management - Salesforce AppExchangeEric Wu
 
Code live with ryan headley code reviews done right
Code live with ryan headley   code reviews done rightCode live with ryan headley   code reviews done right
Code live with ryan headley code reviews done rightJackGuo20
 
Build Your Lightning Rollout Plan - September 2017
Build Your Lightning Rollout Plan - September 2017Build Your Lightning Rollout Plan - September 2017
Build Your Lightning Rollout Plan - September 2017Salesforce Admins
 
Dreamforce: Data You Can Trust
Dreamforce: Data You Can TrustDreamforce: Data You Can Trust
Dreamforce: Data You Can TrustGeraldine Gray
 
Essential Habits for New Admins - Dec 2019
Essential Habits for New Admins - Dec 2019Essential Habits for New Admins - Dec 2019
Essential Habits for New Admins - Dec 2019Salesforce Admins
 
Data import options- Salesforce Dreamforce presentation
Data import options- Salesforce Dreamforce presentationData import options- Salesforce Dreamforce presentation
Data import options- Salesforce Dreamforce presentationRich Spitz
 
Salesforce Partner Forum: The Internet of Things Opportunity
Salesforce Partner Forum: The Internet of Things OpportunitySalesforce Partner Forum: The Internet of Things Opportunity
Salesforce Partner Forum: The Internet of Things OpportunityReidCarlberg
 

Ähnlich wie High Reliability DML and Concurrency Design Patterns for Apex (20)

CodeLive with Cynthia Thomas - Refactoring data dependent code.
CodeLive with Cynthia Thomas - Refactoring data dependent code.CodeLive with Cynthia Thomas - Refactoring data dependent code.
CodeLive with Cynthia Thomas - Refactoring data dependent code.
 
Salesforce Tour Breakout Session: New Features for Salesforce Admins
Salesforce Tour Breakout Session:  New Features for Salesforce AdminsSalesforce Tour Breakout Session:  New Features for Salesforce Admins
Salesforce Tour Breakout Session: New Features for Salesforce Admins
 
API Design for Your Packaged App
API Design for Your Packaged AppAPI Design for Your Packaged App
API Design for Your Packaged App
 
API Design for Your Packaged App
API Design for Your Packaged AppAPI Design for Your Packaged App
API Design for Your Packaged App
 
Getting Started with Salesforce for Non-Profits by Nik Panter
Getting Started with Salesforce for Non-Profits by Nik PanterGetting Started with Salesforce for Non-Profits by Nik Panter
Getting Started with Salesforce for Non-Profits by Nik Panter
 
CodeLive with Adam Daw - Building a mobile friendly geolocation aware candy t...
CodeLive with Adam Daw - Building a mobile friendly geolocation aware candy t...CodeLive with Adam Daw - Building a mobile friendly geolocation aware candy t...
CodeLive with Adam Daw - Building a mobile friendly geolocation aware candy t...
 
Developing on the Salesforce Platform With Clicks, Not Code
Developing on the Salesforce Platform With Clicks, Not CodeDeveloping on the Salesforce Platform With Clicks, Not Code
Developing on the Salesforce Platform With Clicks, Not Code
 
Dreamforce 2014 - Salesforce Python SDK for REST/SOAP APIs
Dreamforce 2014 - Salesforce Python SDK for REST/SOAP APIsDreamforce 2014 - Salesforce Python SDK for REST/SOAP APIs
Dreamforce 2014 - Salesforce Python SDK for REST/SOAP APIs
 
Five Developer Tips Every Admin Needs To Know
Five Developer Tips Every Admin Needs To KnowFive Developer Tips Every Admin Needs To Know
Five Developer Tips Every Admin Needs To Know
 
Getting Starting with Salesforce for Nonprofits
Getting Starting with Salesforce for NonprofitsGetting Starting with Salesforce for Nonprofits
Getting Starting with Salesforce for Nonprofits
 
Top Pipeline Management Reports
Top Pipeline Management ReportsTop Pipeline Management Reports
Top Pipeline Management Reports
 
The ABCs of Salesforce - Rachel Natik
The ABCs of Salesforce - Rachel NatikThe ABCs of Salesforce - Rachel Natik
The ABCs of Salesforce - Rachel Natik
 
Winter '15 Highlights for Salesforce Admins
Winter '15 Highlights for Salesforce AdminsWinter '15 Highlights for Salesforce Admins
Winter '15 Highlights for Salesforce Admins
 
Supercharge your License Management - Salesforce AppExchange
Supercharge your License Management - Salesforce AppExchangeSupercharge your License Management - Salesforce AppExchange
Supercharge your License Management - Salesforce AppExchange
 
Code live with ryan headley code reviews done right
Code live with ryan headley   code reviews done rightCode live with ryan headley   code reviews done right
Code live with ryan headley code reviews done right
 
Build Your Lightning Rollout Plan - September 2017
Build Your Lightning Rollout Plan - September 2017Build Your Lightning Rollout Plan - September 2017
Build Your Lightning Rollout Plan - September 2017
 
Dreamforce: Data You Can Trust
Dreamforce: Data You Can TrustDreamforce: Data You Can Trust
Dreamforce: Data You Can Trust
 
Essential Habits for New Admins - Dec 2019
Essential Habits for New Admins - Dec 2019Essential Habits for New Admins - Dec 2019
Essential Habits for New Admins - Dec 2019
 
Data import options- Salesforce Dreamforce presentation
Data import options- Salesforce Dreamforce presentationData import options- Salesforce Dreamforce presentation
Data import options- Salesforce Dreamforce presentation
 
Salesforce Partner Forum: The Internet of Things Opportunity
Salesforce Partner Forum: The Internet of Things OpportunitySalesforce Partner Forum: The Internet of Things Opportunity
Salesforce Partner Forum: The Internet of Things Opportunity
 

Mehr von 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 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
 

Mehr von 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 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
 
Introduction to MuleSoft
Introduction to MuleSoftIntroduction to MuleSoft
Introduction to MuleSoft
 

Kürzlich hochgeladen

New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
"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
 
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
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
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
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
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
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 

Kürzlich hochgeladen (20)

New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
"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...
 
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
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
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
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
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
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
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
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 

High Reliability DML and Concurrency Design Patterns for Apex

  • 1. High reliability DML and concurrency design patterns for Apex Dan Appleman, Full Circle CRM, CTO Author: Advanced Apex Programming for Salesforce.com and Force.com @danappleman
  • 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. Have you ever seen… EXCEPTION_THROWN [32]|System.QueryException: Record Currently Unavailable: The record you are attempting to edit, or one of its related records, is currently being modified by another user. Please try again. Or FATAL_ERROR System.DmlException: Update failed. First exception on row 0 with id ……………; first error: UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record: []
  • 4. Concurrency Problems The most dangerous kind of bug in all of computer science. Why? Because concurrency problems and bugs can be: ▪Virtually impossible to detect ▪Virtually impossible to reproduce
  • 5. Most of us learn about concurrency errors as children… Dad, can we go to the party? Let me think: NO!
  • 6. Most of us learn about concurrency errors as children… Dad, can we go to the party? Let me think: NO! 15 seconds later Mom can we go to the party? Sure, why not?
  • 7. … or as parents Dad, can we go to the party? Let me check with your mom Pessimistic locking Mom can we go to the party? What did your dad say? Optimistic locking
  • 8. …or in Salesforce Two Salespeople receive simultaneous instructions from two different contacts on an opportunity… This would be very bad
  • 9. …or in Salesforce Two Salespeople receive simultaneous instructions from two different contacts on an opportunity… Salesforce detects the other users’ modification Optimistic locking (so to speak) APEX DOES NOT DO THIS!
  • 10. …or in Salesforce Two Salespeople receive simultaneous instructions from two different contacts on an opportunity… SOQL “For Update” Query Pessimistic locking Block another thread > 10 seconds = UNABLE_TO_LOCK_ROW error
  • 11. Common Lock Conditions ▪ Data skew ▪ Insert or owner change can lock a parent during sharing calculations ▪ After a record update ▪ Records have to be locked to allow rollback in case of an exception ▪ “For Update” query ▪ Explicit lock
  • 12. Common Lock Solutions ▪ Data skew ▪ Reassign record ownership ▪ After a record update ▪ Defer record updates to the end of the execution context ▪ “For Update” query ▪ Avoid or delay where possible ▪ You cannot absolutely prevent these errors ▪ More common on high traffic systems with lots of code
  • 13. Reproducing Lock Errors ▪ Use future calls and anonymous Apex ▪ You can simulate them in unit tests
  • 14. Handling Lock Errors ▪ In triggers and VisualForce ▪ Let the user deal with them ▪ In asynchronous code ▪ Logging ▪ Recovery
  • 15. For More Information Advanced Apex Programming for Salesforce.com and Force.com – Second Edition • • • • • Incorporates changes through Winter 14 Designing for CPU Time limits Extended chapter on triggers Extended chapter on asynchronous patterns New chapter on concurrency patterns
  • 16. All About Full Circle CRM Full Circle CRM develops native Salesforce.com applications that enable marketers to accurately track and measure marketing campaign performance directly in Salesforce ▪ Bridge the information gap between leads and contacts ▪ Obtain complete and detailed campaign performance metrics ▪ Develop advanced campaign attribution and influence analytics Booth 1324 Moscone North
  • 17. Download sample code for this session at www.AdvancedApex.com/Dreamforce13
  • 18. 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