Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Route your triggers like a pro #DF18

87 views

Published on

Presentation held by Christian Szandor Knapp and Daniel Stange at Dreamforce 2018, September 24th, in San Francisco.

Did you have a closer look at your trigger handlers recently. In many cases, platform events can encapsulate and orchestrate your business logic much cleaner than triggers and are easier to integrate with from outside of your org. Custom metadata types enable you to make your triggers and platform event handlers configurable for yourself and - caveat emptor - customizable and replaceable across namespaces. And what about this new Trigger Context Enum? Learn to route your business logic like a pro and to conduct the traffic in your org and/or packages in reliable, performant and - if you want to - configurable ways.

Published in: Technology
  • Be the first to comment

Route your triggers like a pro #DF18

  1. 1. Route Your Triggers Like a Pro @ch_sz_knapp Christian Szandor Knapp Lead Developer, appero Daniel Stange Technical Architect, DIA die.interaktiven @stangomat
  2. 2. 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. Statement under the Private Securities Litigation Reform Act of 1995 Forward-Looking Statement
  3. 3. Agenda • Setting the Stage: A Trigger Tale • Shifting Gears: Custom Metadata • Shifting Streams: Decouple Transactions from Business Events • Aiming High: Try the MyTriggers Framework Route your Triggers like a Pro
  4. 4. A Trigger Tale I: Timeless Truths Developer wisdom • Code has to be outside of Triggers • Use Maps and Sets instead of Lists • One Trigger per sObject • Use try / catch / rollback What We All Learned Early On Platform Wisdom • Triggers fire on CRUD • Triggers run synchronously When did you last step back to wonder how to design your Trigger handling?
  5. 5. A Trigger Tale II: The Disturbance of the Force • Both UI and Platform are more and more event driven Lightning Experience, Platform Events • Development paradigms focus on modularity Salesforce DX & Developer Controlled Packages • Platform enhancements allow for sophisticated enterprise patterns Custom Metadata Types, Callable Interface (WI19), Force DI Library It's 2018 and Change Happened
  6. 6. Setting the Stage At the Beginning, Everything Seemed Straightforward
  7. 7. Setting the Stage And Here’s What We Ended up With
  8. 8. The Transactional Model over Time Let’s Step Back a Moment to Abstract Time Imagine somebody introduces a new validation rule
  9. 9. Shifting Gears De-Coupling Triggers with Custom Metadata Types
  10. 10. De-Coupling Cogs with Custom Metadata Types Introducing Maximal Configurability for Transaction Control • Overcome tight coupling of cogs by pulling them apart • Distribute traction by configurable conveyor belts • Add new functionality without ever touching Trigger code
  11. 11. De-Coupling Cogs with Custom Metadata Types Introducing Maximal Configurability for Transaction Control
  12. 12. Decouple & Reorder Handlers from a Business Perspective Use ListViews to Get a Grab on Things
  13. 13. De-Coupling Cogs with Custom Metadata Types Business Logic Is Loosely Linked to Platform Logic via Configuration
  14. 14. De-Coupling Cogs with Code
  15. 15. Shifting Streams De-Coupling Transactions from Business Events
  16. 16. Extend the Reach of Your Triggers with Events • Events are “Triggers“ to/from internal and external systems • Events aren‘t tied to any logic or sObject • Jump out of any context persistently - even try {} / catch {} rollback Handling platform events is... Handling Just Another After Insert Trigger! Therefore: myTriggers is able to manage your Triggers and Events
  17. 17. Calling Back to the User There is only one kind of notification in LEX: asynchronous We can create our own by leveraging a) PushTopics / Streaming API b) a Custom Component in the Utility bar … that is always around in the UI … so we can pop up a notification … or a whole transaction log A Toast Is a Toast Is a Toast
  18. 18. Trigger or Events or Both Choose What Best Fits Your Needs
  19. 19. Synergies: Trigger and Events There Is No Event without a Trigger on the Platform Platform Event orchestration uses the same Trigger Framework. Note: There’s only AfterInsert for Events. Our ERP can now send a “low stock level” Event and Trigger record updates and notifications through the same framework.
  20. 20. Tradeoffs: Trigger and Events Event • External subscribers or internal long-running processes • you don‘t need immediate results Trigger • When you need immediate results • End-to-end control over the transaction • And don't forget the joys of the "Before"-context...
  21. 21. Aiming High Takeaways, Next Steps and Resources
  22. 22. Where Can You Take It From Here? • Download MyTriggers from https://www.github.com/appero_com/MyTriggers Or install our package (unlocked DCP) from http://bit.ly/MyTriggersDF18 • Start modelling your Triggers business process centric instead of sObject centric • Break down business processes into modular steps that can be invoked • in synchronous... • or asynchronous contexts Instant Notification App Apex Enterprise PatternsCustom Metadata Types
  23. 23. Last Words of Caution: Data Integrity • Deactivating Trigger / Event handlers on the fly is great fun • Forgetting to turn them back on again, is not • There’s a reason why Triggers are hard to get by because they safeguard your data integrity
  24. 24. Don’t Learn the Hard Way: Resources Essential Reads • Dan Appleman: Advanced Apex Programming • Andrew Fawcett: Force.com Enterprise Architecture Referenced Technologies • Force DI: https://github.com/afawcett/force-di • MetadataTriggerHandler by Aiden Harding: https://bitbucket.org/aidan_harding/metadatatriggerhandler • Streams by BigAssForce: https://bigass.secure.force.com/streams • TriggerX by Sebastian Wagner: https://github.com/se6wagner/TriggerX Recommended Reads and Repos

×