Introduction to Apex Triggers


Published on

"We'll need an Apex trigger to do that." Sound familiar? Take your advanced Admin skills to the next level by developing Apex triggers to solve complex business requirements that can't be implemented using just the configuration-driven features of Join us to learn when and how to write your first Apex trigger, and some best practices for making them effective.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Introduction to Apex Triggers

  1. 1. Introduction to Apex Triggers Arming the Dangerous Iman Maghroori, Principal Sales Engineer @IMaghroori Doug Merrett, Principal Architect @justinbeiber
  2. 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, 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 products, and utilization and selling to larger enterprise customers. Further information on potential factors that could affect the financial results of, 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., inc. assumes no obligation and does not intend to update these forward-looking statements.
  3. 3. Iman Maghroori Principal Sales Engineer @IMaghroori
  4. 4. Doug Merrett Principal Architect – Northern Europe @justinbeiber
  5. 5. Here is the Plan What is a Trigger? When / Why Trigger Deconstruction Tools Resources Q&A
  6. 6. SURVEY: RAISE YOUR HAND IF YOU’VE…      Created a Custom Field? Created a Workflow/Approval rules? Written any code before? Written Apex code? Written a Trigger before?
  7. 7. What is a Trigger?
  8. 8. What is a Trigger? “…is procedural code that is automatically executed in response to certain events in a database…” - Wikipedia
  9. 9. What is a Trigger? “ …custom code that fires when a record is created, updated or deleted.” -Iman Maghroori
  10. 10. What Happens When You Hit “Save”?
  11. 11. What Happens When You Hit “Save”? 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. Old values are overwritten System Validation Rules Apex (before) triggers Custom Validation Rules Record saved to DB (not committed) Record reloaded from DB Apex (after) triggers Assignment Rules Auto-Response Rules Workflow Rules Escalation Rules Rollup Summary Formulas updated Database Commit Post-commit logic (Sending emails)
  12. 12. Now You’re Dangerous…
  13. 13. When Should You Use Triggers? When all other options fail Don’t write code if you don’t have to  Easier to maintain  Easier to change  Faster to deploy
  14. 14. Workflow Can… Update Fields Assign Tasks Send Emails Send Outbound Messages (Integrations)
  15. 15. Workflow Cannot… Create Other Records  Automatically create child records Complex Calculations  Calculate total revenue from child accounts Automatically Submit Records for Approval Delete Records
  16. 16. Apex: The Programming Language of Object-oriented language Java-like syntax 6 Billion+ Lines of Apex
  17. 17. Why Apex? Runs in the Cloud Integrated to Your Data Lots of prebuilt capability Testing Framework Backward Compatibility
  18. 18. The Platform is a Multi-Tenant Environment
  19. 19. Use Case: UberJet
  20. 20. Create Invoice Trigger
  21. 21. Mark the Jet as Booked Trigger
  22. 22. Test Your Code!
  23. 23. 75% Minimum Code Coverage Before You Deploy We check for the %, you should check for all the possible use cases.
  24. 24. How to Deploy to Production? • Make sure your code passes the tests & test coverage • Create an “Outbound Change Set” and add your updates to it • Push the Outbound Change Set to your Production Environment • Accept the Inbound Change Set in your Production Environment. • Setup → Deploy → Inbound Change Sets → [Change Set] → Deploy
  25. 25. Next Steps to Level Up • Developer Environment • Apex Workbook • To Learn More
  26. 26. Where Can I Go for Help? • • • • • • • Training / Certifications Code Share Developer Community Apex Guide Security Information Help & Training Take it to the Next Level: Professional Services
  27. 27. Any Questions?