SlideShare a Scribd company logo
1 of 26
Apex Trigger Debugging
Solving the Hard Problems
Cory Cowgill, The Warranty Group
@Cory Cowgill
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.
Apex Trigger Debugging
• Apex Triggers are a powerful feature of the Salesforce platfrom. They allow for
tremendous flexibility in building custom applications on the platform. Because they
execute within the database layer of the platform they can be used for multiple use
cases across an application.
• This flexibility can be a double edged sword. When you build triggers you are
exposing additional risk for errors into your application. During this session we will
be exploring some of these common errors and how you can solve for them.
Agenda
 Apex Triggers Overview
• Technical Scope of Session
• Basics of Apex Triggers
• Tools to work with Triggers

 Common Trigger Problems & Resolutions
• Cascading Triggers
• Apex Governor Limits
• Null Reference Errors
• Too Many SOQL Queries
Technical Scope
 This is a Apex Trigger Session!
• Apex Trigger Code
• Apex Classes
• Stack Traces
• Trigger Execution Context

 This session will be code and stack trace heavy.
• Code not Clicks
Basics of Apex Triggers
 Execute at the database layer via DML (Data Manipulation Language)
• Insert, Update, Upsert, Delete, Un-Delete
• Before, After

 What does this mean?
• Regardless of invocation point they will fire
• Standard Pages, Visualforce Pages, API calls, etc.
Basics of Apex Triggers
 Order of Execution
• 1. Before Trigger Execution
• 2. System Validation Rules Execution
• 3. Record Saved in Memory (Not DB) (ID Assigned)
• 4. After Trigger Execution
• 5. Assignment Rules
• 6. Auto-Response Rules
• 7. Workflow Rules (Trigger Step 1 If Field Update)
• Full Order:
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers_or
der_of_execution.htm
Trigger Tools
 Force.com IDE
• Anonymous Apex
• Result Logs
• Unit Tests
Trigger Tools
 Salesforce Platform Debug Logs
• Stack Traces
• Per User Debugging
Apex Governor Limits
Example Use Cases
1. When an Opportunity is “Closed Won”, automatically generate a Invoice.
2. When an Opportunity Product is added to an Opportunity, automatically
update the Opportunity Amount.
3. When an Invoice is generated, automatically link it to the Account and
update the Account Client Lifetime Revenue.
4. When an Account is set to start invoice setup, automatically link the
mailing Contact to the Invoices.
Understand Your Data Model – Schema Builder
Complex Problem #1 – Cascading Triggers
 Definition
• A trigger updates another record, which updates another record, which eventually
consumes all the trigger resources forcing an error
Complex Problem #1 – Cascading Triggers
Complex Problem #1 – Cascading Triggers
 Resolution
• There is no silver bullet for this issue
• Static Variables can be used to prevent recursive or cascading logic from
happening
• Reducing the number of Apex triggers and following best practices can mitigate
this issue
• Logic can be moved to Batch Apex if it is too large or complex
Complex Problem #2 – Null Reference Errors
 Definition
• A trigger attempts to access a instance of an object that is empty
• A trigger attempts to access a property of an object that is empty
• This is common error amongst all programming languages
• Manifests itself in Apex the same as other languages (Java, etc)
Complex Problem #2 – Null Reference Errors
Complex Problem #2 – Null Reference Errors
 Resolution
• Perform null checks in your Apex code
• Ensure SOQL is pulling all fields referenced in your Apex code, consider using
Apex DAO objects to encapsulate queries
• Configure Objects to have default (non-null) values
Complex Problem #3 – Too Many SOQL Queries
 Definition
• In a given Apex Trigger context, you cannot execute more than 100 SOQL
Queries
• This is typically due to either simple for loops executing SOQL, or more complex
cascading trigger logic.
Complex Problem #3 – Too Many SOQL Queries
Complex Problem #3 – Too Many SOQL Queries
 Resolution
• Remove SOQL from for loops, while loops, or recursively called methods
• For large query logic, consider moving the logic into Apex Batch instead of an
Apex trigger
• Condense Child-Parent into one Query
• Make sure that triggers are bulkified
Slide parts
Slide parts
Slide parts
Slide parts

More Related Content

What's hot

Salesforce interview questions walkthrough
Salesforce interview questions walkthroughSalesforce interview questions walkthrough
Salesforce interview questions walkthroughShivam Srivastava
 
Introduction to the Salesforce Security Model
Introduction to the Salesforce Security ModelIntroduction to the Salesforce Security Model
Introduction to the Salesforce Security ModelSalesforce Developers
 
Salesforce Integration Pattern Overview
Salesforce Integration Pattern OverviewSalesforce Integration Pattern Overview
Salesforce Integration Pattern OverviewDhanik Sahni
 
Lwc presentation
Lwc presentationLwc presentation
Lwc presentationNithesh N
 
Introduction to Lightning Web Component
Introduction to Lightning Web Component Introduction to Lightning Web Component
Introduction to Lightning Web Component SmritiSharan1
 
CNX16 - Connecting the Cloud: Marketing Cloud Connect
CNX16 - Connecting the Cloud: Marketing Cloud ConnectCNX16 - Connecting the Cloud: Marketing Cloud Connect
CNX16 - Connecting the Cloud: Marketing Cloud ConnectCloud_Services
 
Lightning web components
Lightning web components Lightning web components
Lightning web components Cloud Analogy
 
Lightning Web Component in Salesforce
Lightning Web Component in SalesforceLightning Web Component in Salesforce
Lightning Web Component in SalesforceJitendra Zaa
 
Sales Cloud Lightning Migration Best Practices
Sales Cloud Lightning Migration Best PracticesSales Cloud Lightning Migration Best Practices
Sales Cloud Lightning Migration Best PracticesSalesforce Partners
 
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
 
Salesforce Interview Questions And Answers | Salesforce Tutorial | Salesforce...
Salesforce Interview Questions And Answers | Salesforce Tutorial | Salesforce...Salesforce Interview Questions And Answers | Salesforce Tutorial | Salesforce...
Salesforce Interview Questions And Answers | Salesforce Tutorial | Salesforce...Edureka!
 
Introduction to Salesforce.com
Introduction to Salesforce.comIntroduction to Salesforce.com
Introduction to Salesforce.comEdureka!
 
Salesforce development lifecycle
Salesforce development lifecycleSalesforce development lifecycle
Salesforce development lifecyclegiridhar007
 
How to Build an AppExchange Strategy
How to Build an AppExchange StrategyHow to Build an AppExchange Strategy
How to Build an AppExchange StrategySalesforce 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
 
DevOps Center_ArchitectGroup
DevOps Center_ArchitectGroup DevOps Center_ArchitectGroup
DevOps Center_ArchitectGroup AmeyKulkarni84
 
Managing the Role Hierarchy at Enterprise Scale
Managing the Role Hierarchy at Enterprise ScaleManaging the Role Hierarchy at Enterprise Scale
Managing the Role Hierarchy at Enterprise ScaleSalesforce Developers
 

What's hot (20)

Salesforce interview questions walkthrough
Salesforce interview questions walkthroughSalesforce interview questions walkthrough
Salesforce interview questions walkthrough
 
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
 
Salesforce Integration Pattern Overview
Salesforce Integration Pattern OverviewSalesforce Integration Pattern Overview
Salesforce Integration Pattern Overview
 
Lwc presentation
Lwc presentationLwc presentation
Lwc presentation
 
Introduction to Lightning Web Component
Introduction to Lightning Web Component Introduction to Lightning Web Component
Introduction to Lightning Web Component
 
CNX16 - Connecting the Cloud: Marketing Cloud Connect
CNX16 - Connecting the Cloud: Marketing Cloud ConnectCNX16 - Connecting the Cloud: Marketing Cloud Connect
CNX16 - Connecting the Cloud: Marketing Cloud Connect
 
Dependency Injection with Apex
Dependency Injection with ApexDependency Injection with Apex
Dependency Injection with Apex
 
Lightning web components
Lightning web components Lightning web components
Lightning web components
 
Lightning Web Component in Salesforce
Lightning Web Component in SalesforceLightning Web Component in Salesforce
Lightning Web Component in Salesforce
 
Sales Cloud Lightning Migration Best Practices
Sales Cloud Lightning Migration Best PracticesSales Cloud Lightning Migration Best Practices
Sales Cloud Lightning Migration Best Practices
 
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
 
Salesforce Interview Questions And Answers | Salesforce Tutorial | Salesforce...
Salesforce Interview Questions And Answers | Salesforce Tutorial | Salesforce...Salesforce Interview Questions And Answers | Salesforce Tutorial | Salesforce...
Salesforce Interview Questions And Answers | Salesforce Tutorial | Salesforce...
 
Introduction to Salesforce.com
Introduction to Salesforce.comIntroduction to Salesforce.com
Introduction to Salesforce.com
 
Salesforce development lifecycle
Salesforce development lifecycleSalesforce development lifecycle
Salesforce development lifecycle
 
How to Build an AppExchange Strategy
How to Build an AppExchange StrategyHow to Build an AppExchange Strategy
How to Build an AppExchange Strategy
 
Salesforce integration best practices columbus meetup
Salesforce integration best practices   columbus meetupSalesforce integration best practices   columbus meetup
Salesforce integration best practices columbus meetup
 
DevOps Center_ArchitectGroup
DevOps Center_ArchitectGroup DevOps Center_ArchitectGroup
DevOps Center_ArchitectGroup
 
Managing the Role Hierarchy at Enterprise Scale
Managing the Role Hierarchy at Enterprise ScaleManaging the Role Hierarchy at Enterprise Scale
Managing the Role Hierarchy at Enterprise Scale
 
An Introduction to Lightning Web Components
An Introduction to Lightning Web ComponentsAn Introduction to Lightning Web Components
An Introduction to Lightning Web Components
 

Viewers also liked

Salesforce Meetup 18 April 2015 - Apex Trigger & Scheduler Framworks
Salesforce Meetup 18 April 2015 - Apex Trigger & Scheduler FramworksSalesforce Meetup 18 April 2015 - Apex Trigger & Scheduler Framworks
Salesforce Meetup 18 April 2015 - Apex Trigger & Scheduler FramworksSumitkumar Shingavi
 
Triggers and order of execution1
Triggers and order of execution1Triggers and order of execution1
Triggers and order of execution1Prabhakar Sharma
 
Spring '13 Release Developer Preview Webinar
Spring '13 Release Developer Preview WebinarSpring '13 Release Developer Preview Webinar
Spring '13 Release Developer Preview WebinarSalesforce Developers
 
Brisbane Salesforce User Group - May 2015 - Lightning Process Builder
Brisbane Salesforce User Group - May 2015 - Lightning Process BuilderBrisbane Salesforce User Group - May 2015 - Lightning Process Builder
Brisbane Salesforce User Group - May 2015 - Lightning Process BuilderKevin Akermanis
 
Build Reliable Asynchronous Code with Queueable Apex
Build Reliable Asynchronous Code with Queueable ApexBuild Reliable Asynchronous Code with Queueable Apex
Build Reliable Asynchronous Code with Queueable ApexSalesforce Developers
 
Intro to Apex - Salesforce Force Friday Webinar
Intro to Apex - Salesforce Force Friday Webinar Intro to Apex - Salesforce Force Friday Webinar
Intro to Apex - Salesforce Force Friday Webinar Abhinav Gupta
 
Apex Testing and Best Practices
Apex Testing and Best PracticesApex Testing and Best Practices
Apex Testing and Best PracticesJitendra Zaa
 

Viewers also liked (12)

Salesforce Meetup 18 April 2015 - Apex Trigger & Scheduler Framworks
Salesforce Meetup 18 April 2015 - Apex Trigger & Scheduler FramworksSalesforce Meetup 18 April 2015 - Apex Trigger & Scheduler Framworks
Salesforce Meetup 18 April 2015 - Apex Trigger & Scheduler Framworks
 
Triggers and order of execution1
Triggers and order of execution1Triggers and order of execution1
Triggers and order of execution1
 
Governor limits
Governor limitsGovernor limits
Governor limits
 
Introduction to Apex Triggers
Introduction to Apex TriggersIntroduction to Apex Triggers
Introduction to Apex Triggers
 
Spring '13 Release Developer Preview Webinar
Spring '13 Release Developer Preview WebinarSpring '13 Release Developer Preview Webinar
Spring '13 Release Developer Preview Webinar
 
Brisbane Salesforce User Group - May 2015 - Lightning Process Builder
Brisbane Salesforce User Group - May 2015 - Lightning Process BuilderBrisbane Salesforce User Group - May 2015 - Lightning Process Builder
Brisbane Salesforce User Group - May 2015 - Lightning Process Builder
 
Build Reliable Asynchronous Code with Queueable Apex
Build Reliable Asynchronous Code with Queueable ApexBuild Reliable Asynchronous Code with Queueable Apex
Build Reliable Asynchronous Code with Queueable Apex
 
Apex Nirvana
Apex NirvanaApex Nirvana
Apex Nirvana
 
Intro to Apex - Salesforce Force Friday Webinar
Intro to Apex - Salesforce Force Friday Webinar Intro to Apex - Salesforce Force Friday Webinar
Intro to Apex - Salesforce Force Friday Webinar
 
Apex code (Salesforce)
Apex code (Salesforce)Apex code (Salesforce)
Apex code (Salesforce)
 
Apex Testing and Best Practices
Apex Testing and Best PracticesApex Testing and Best Practices
Apex Testing and Best Practices
 
Apex Design Patterns
Apex Design PatternsApex Design Patterns
Apex Design Patterns
 

Similar to Apex Trigger Debugging Tips

Designing custom REST and SOAP interfaces on Force.com
Designing custom REST and SOAP interfaces on Force.comDesigning custom REST and SOAP interfaces on Force.com
Designing custom REST and SOAP interfaces on Force.comSteven Herod
 
Designing Custom REST and SOAP Interfaces on Force.com
Designing Custom REST and SOAP Interfaces on Force.comDesigning Custom REST and SOAP Interfaces on Force.com
Designing Custom REST and SOAP Interfaces on Force.comSalesforce Developers
 
Building Command-line Tools with the Tooling API
Building Command-line Tools with the Tooling APIBuilding Command-line Tools with the Tooling API
Building Command-line Tools with the Tooling APIJeff Douglas
 
Best Practices for Team Development in a Single Org
Best Practices for Team Development in a Single OrgBest Practices for Team Development in a Single Org
Best Practices for Team Development in a Single OrgSalesforce Developers
 
Elevate Madrid Essentials - Advance Track
Elevate Madrid Essentials - Advance TrackElevate Madrid Essentials - Advance Track
Elevate Madrid Essentials - Advance TrackCarolEnLaNube
 
Apex Nuances: Transitioning to Force.com Development
Apex Nuances: Transitioning to Force.com DevelopmentApex Nuances: Transitioning to Force.com Development
Apex Nuances: Transitioning to Force.com DevelopmentSalesforce Developers
 
Manage Development in Your Org with Salesforce Governance Framework
Manage Development in Your Org with Salesforce Governance FrameworkManage Development in Your Org with Salesforce Governance Framework
Manage Development in Your Org with Salesforce Governance FrameworkSalesforce Developers
 
DevOps in Salesforce AppCloud
DevOps in Salesforce AppCloudDevOps in Salesforce AppCloud
DevOps in Salesforce AppCloudrsg00usa
 
Self-Service Secure Test and Release Pipelines
Self-Service Secure Test and Release PipelinesSelf-Service Secure Test and Release Pipelines
Self-Service Secure Test and Release PipelinesSalesforce Engineering
 
Scaling to Millions of Devices and Billions of Events
Scaling to Millions of Devices and Billions of EventsScaling to Millions of Devices and Billions of Events
Scaling to Millions of Devices and Billions of EventsSalesforce Developers
 
Building Apps Faster with Lightning and Winter '17
Building Apps Faster with Lightning and Winter '17Building Apps Faster with Lightning and Winter '17
Building Apps Faster with Lightning and Winter '17Mark Adcock
 
Building apps faster with lightning and winter '17
Building apps faster with lightning and winter '17Building apps faster with lightning and winter '17
Building apps faster with lightning and winter '17Salesforce Developers
 
Bug Hunting with the Salesforce Developer Console
Bug Hunting with the Salesforce Developer ConsoleBug Hunting with the Salesforce Developer Console
Bug Hunting with the Salesforce Developer ConsoleMatthew Poe
 
An Admin's Guide to the Developer Console by Francis Pindar
An Admin's Guide to the Developer Console by Francis PindarAn Admin's Guide to the Developer Console by Francis Pindar
An Admin's Guide to the Developer Console by Francis PindarSalesforce Admins
 
Salesforce Multitenant Architecture: How We Do the Magic We Do
Salesforce Multitenant Architecture: How We Do the Magic We DoSalesforce Multitenant Architecture: How We Do the Magic We Do
Salesforce Multitenant Architecture: How We Do the Magic We DoSalesforce Developers
 
Managing Your Batch and Scheduled Apex Processes with Relax
Managing Your Batch and Scheduled Apex Processes with RelaxManaging Your Batch and Scheduled Apex Processes with Relax
Managing Your Batch and Scheduled Apex Processes with RelaxSalesforce Developers
 

Similar to Apex Trigger Debugging Tips (20)

Designing custom REST and SOAP interfaces on Force.com
Designing custom REST and SOAP interfaces on Force.comDesigning custom REST and SOAP interfaces on Force.com
Designing custom REST and SOAP interfaces on Force.com
 
Designing Custom REST and SOAP Interfaces on Force.com
Designing Custom REST and SOAP Interfaces on Force.comDesigning Custom REST and SOAP Interfaces on Force.com
Designing Custom REST and SOAP Interfaces on Force.com
 
Building Command-line Tools with the Tooling API
Building Command-line Tools with the Tooling APIBuilding Command-line Tools with the Tooling API
Building Command-line Tools with the Tooling API
 
Best Practices for Team Development in a Single Org
Best Practices for Team Development in a Single OrgBest Practices for Team Development in a Single Org
Best Practices for Team Development in a Single Org
 
Elevate Madrid Essentials - Advance Track
Elevate Madrid Essentials - Advance TrackElevate Madrid Essentials - Advance Track
Elevate Madrid Essentials - Advance Track
 
Security Boundaries in Apex
Security Boundaries in ApexSecurity Boundaries in Apex
Security Boundaries in Apex
 
Apex Nuances: Transitioning to Force.com Development
Apex Nuances: Transitioning to Force.com DevelopmentApex Nuances: Transitioning to Force.com Development
Apex Nuances: Transitioning to Force.com Development
 
Manage Development in Your Org with Salesforce Governance Framework
Manage Development in Your Org with Salesforce Governance FrameworkManage Development in Your Org with Salesforce Governance Framework
Manage Development in Your Org with Salesforce Governance Framework
 
DevOps in Salesforce AppCloud
DevOps in Salesforce AppCloudDevOps in Salesforce AppCloud
DevOps in Salesforce AppCloud
 
Self-Service Secure Test and Release Pipelines
Self-Service Secure Test and Release PipelinesSelf-Service Secure Test and Release Pipelines
Self-Service Secure Test and Release Pipelines
 
Scaling to Millions of Devices and Billions of Events
Scaling to Millions of Devices and Billions of EventsScaling to Millions of Devices and Billions of Events
Scaling to Millions of Devices and Billions of Events
 
Building Apps Faster with Lightning and Winter '17
Building Apps Faster with Lightning and Winter '17Building Apps Faster with Lightning and Winter '17
Building Apps Faster with Lightning and Winter '17
 
Building apps faster with lightning and winter '17
Building apps faster with lightning and winter '17Building apps faster with lightning and winter '17
Building apps faster with lightning and winter '17
 
Force.com Friday : Intro to Apex
Force.com Friday : Intro to Apex Force.com Friday : Intro to Apex
Force.com Friday : Intro to Apex
 
Apex for Admins: Beyond the Basics
Apex for Admins: Beyond the BasicsApex for Admins: Beyond the Basics
Apex for Admins: Beyond the Basics
 
Coding in the App Cloud
Coding in the App CloudCoding in the App Cloud
Coding in the App Cloud
 
Bug Hunting with the Salesforce Developer Console
Bug Hunting with the Salesforce Developer ConsoleBug Hunting with the Salesforce Developer Console
Bug Hunting with the Salesforce Developer Console
 
An Admin's Guide to the Developer Console by Francis Pindar
An Admin's Guide to the Developer Console by Francis PindarAn Admin's Guide to the Developer Console by Francis Pindar
An Admin's Guide to the Developer Console by Francis Pindar
 
Salesforce Multitenant Architecture: How We Do the Magic We Do
Salesforce Multitenant Architecture: How We Do the Magic We DoSalesforce Multitenant Architecture: How We Do the Magic We Do
Salesforce Multitenant Architecture: How We Do the Magic We Do
 
Managing Your Batch and Scheduled Apex Processes with Relax
Managing Your Batch and Scheduled Apex Processes with RelaxManaging Your Batch and Scheduled Apex Processes with Relax
Managing Your Batch and Scheduled Apex Processes with Relax
 

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
 
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
 
Modern App Dev: Modular Development Strategies
Modern App Dev: Modular Development StrategiesModern App Dev: Modular Development Strategies
Modern App Dev: Modular Development StrategiesSalesforce 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
 
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
 
Modern App Dev: Modular Development Strategies
Modern App Dev: Modular Development StrategiesModern App Dev: Modular Development Strategies
Modern App Dev: Modular Development Strategies
 
Dreamforce Developer Recap
Dreamforce Developer RecapDreamforce Developer Recap
Dreamforce Developer Recap
 
Vs Code for Salesforce Developers
Vs Code for Salesforce DevelopersVs Code for Salesforce Developers
Vs Code for Salesforce Developers
 

Recently uploaded

Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
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
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
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
 
"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
 
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
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
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
 
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
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
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
 
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
 

Recently uploaded (20)

Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
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
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
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
 
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
 
"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
 
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
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
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
 
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
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
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
 
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
 

Apex Trigger Debugging Tips

  • 1. Apex Trigger Debugging Solving the Hard Problems Cory Cowgill, The Warranty Group @Cory Cowgill
  • 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. Apex Trigger Debugging • Apex Triggers are a powerful feature of the Salesforce platfrom. They allow for tremendous flexibility in building custom applications on the platform. Because they execute within the database layer of the platform they can be used for multiple use cases across an application. • This flexibility can be a double edged sword. When you build triggers you are exposing additional risk for errors into your application. During this session we will be exploring some of these common errors and how you can solve for them.
  • 4. Agenda  Apex Triggers Overview • Technical Scope of Session • Basics of Apex Triggers • Tools to work with Triggers  Common Trigger Problems & Resolutions • Cascading Triggers • Apex Governor Limits • Null Reference Errors • Too Many SOQL Queries
  • 5. Technical Scope  This is a Apex Trigger Session! • Apex Trigger Code • Apex Classes • Stack Traces • Trigger Execution Context  This session will be code and stack trace heavy. • Code not Clicks
  • 6. Basics of Apex Triggers  Execute at the database layer via DML (Data Manipulation Language) • Insert, Update, Upsert, Delete, Un-Delete • Before, After  What does this mean? • Regardless of invocation point they will fire • Standard Pages, Visualforce Pages, API calls, etc.
  • 7. Basics of Apex Triggers  Order of Execution • 1. Before Trigger Execution • 2. System Validation Rules Execution • 3. Record Saved in Memory (Not DB) (ID Assigned) • 4. After Trigger Execution • 5. Assignment Rules • 6. Auto-Response Rules • 7. Workflow Rules (Trigger Step 1 If Field Update) • Full Order: http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers_or der_of_execution.htm
  • 8. Trigger Tools  Force.com IDE • Anonymous Apex • Result Logs • Unit Tests
  • 9. Trigger Tools  Salesforce Platform Debug Logs • Stack Traces • Per User Debugging
  • 11. Example Use Cases 1. When an Opportunity is “Closed Won”, automatically generate a Invoice. 2. When an Opportunity Product is added to an Opportunity, automatically update the Opportunity Amount. 3. When an Invoice is generated, automatically link it to the Account and update the Account Client Lifetime Revenue. 4. When an Account is set to start invoice setup, automatically link the mailing Contact to the Invoices.
  • 12. Understand Your Data Model – Schema Builder
  • 13. Complex Problem #1 – Cascading Triggers  Definition • A trigger updates another record, which updates another record, which eventually consumes all the trigger resources forcing an error
  • 14. Complex Problem #1 – Cascading Triggers
  • 15. Complex Problem #1 – Cascading Triggers  Resolution • There is no silver bullet for this issue • Static Variables can be used to prevent recursive or cascading logic from happening • Reducing the number of Apex triggers and following best practices can mitigate this issue • Logic can be moved to Batch Apex if it is too large or complex
  • 16. Complex Problem #2 – Null Reference Errors  Definition • A trigger attempts to access a instance of an object that is empty • A trigger attempts to access a property of an object that is empty • This is common error amongst all programming languages • Manifests itself in Apex the same as other languages (Java, etc)
  • 17. Complex Problem #2 – Null Reference Errors
  • 18. Complex Problem #2 – Null Reference Errors  Resolution • Perform null checks in your Apex code • Ensure SOQL is pulling all fields referenced in your Apex code, consider using Apex DAO objects to encapsulate queries • Configure Objects to have default (non-null) values
  • 19. Complex Problem #3 – Too Many SOQL Queries  Definition • In a given Apex Trigger context, you cannot execute more than 100 SOQL Queries • This is typically due to either simple for loops executing SOQL, or more complex cascading trigger logic.
  • 20. Complex Problem #3 – Too Many SOQL Queries
  • 21. Complex Problem #3 – Too Many SOQL Queries  Resolution • Remove SOQL from for loops, while loops, or recursively called methods • For large query logic, consider moving the logic into Apex Batch instead of an Apex trigger • Condense Child-Parent into one Query • Make sure that triggers are bulkified
  • 22.

Editor's Notes

  1. Dry Run Notes: Mission Slide – Apex Triggers are powerful, but…. ETC Bouncing around too much will make it feel like your just debugging. Very Specifically this is the problem, this is why we are seeing it. “This is failing because”. Slide Deck – If you pop-out to something that helps solve the problem. Add in presentation a title slide that says Debug Logs. Then pop to power-point. Basically a bookmark. Point out they are useful because they allow you to track user behavior. Maybe worthwhile to take the two pieces of code. Static Variable in Apex Trigger. DAO class give a brief example. Shoutout to Schema Browser so they know they can get to it. Threw Validation Rule throw.