SlideShare a Scribd company logo
@puntadreamin #PD17
Writing Highly Genericized Code Using
Dynamic Apex and the Tooling API
Adam Olshansky
Salesforce Developer, Contractor at YouTube
Salesforce MVP, 13X Certified
AdamToArchitect.com
@adam17amo
¡Estoy feliz de estar en
Punta del Este!
Agenda
•  Overview of generic code for Apex
•  Dynamic Code in Salesforce
•  Tooling API
Generic Programming in Apex
What problems are we solving for?
•  Rigid or fragile code
•  Poor Reusability
•  Lots of patches/quick fixes
•  Duplicate code
•  Overly complicated data structures
•  Maps of maps of maps…
Who are we talking to today?
•  ISV developers
•  Don’t know all conditions of customer orgs
•  Individual app developers
•  May need to accept input from clients/customers
•  Any developer accepting user input
•  Tailor your queries and results based on user conditions
Different Ways of Writing Code: Static vs. Dynamic
Static
•  Generated at compile time
•  Hard coded
•  Doesn’t usually have dependencies
•  Works well if you know what’s in the
org
•  Most commonly used by developers at
a company developing for their own
org
Dynamic/Generic
•  Generated at run time
•  Dependent on user input
•  May have org-specific dependencies
•  Works well if you DON’T know what’s in the
org
•  Most commonly used by developers whose
code needs to run in customized orgs
2 Different Ways of Writing Code
Tradeoffs
​ Positives
•  More detailed information
•  Less chance of an error down the road
•  Endless possibilities
​ Negatives
•  More code to write
•  More code to test
•  Less readability
Tools of the Trade
Several Ways in Salesforce
•  Custom Settings/Metadata
•  Dynamic Apex
•  Dynamic Visualforce
•  Dynamic SOQL
•  Limits class
•  Schema class
Dynamic Apex
Dynamic Controller
Dynamic Visualforce
Dynamic SOQL
•  Don’t always know what parameters are available in a user’s org
•  In your org this will work
•  What if your customer doesn’t have record types defined for Lead?
Limits Class
•  Limits.getDMLRows();
•  Limits.getDMLStatements();
•  Limits.getHeapSize();
•  Limits.getQueries();
•  Limits.getQueryRows();
•  bit.ly/apexlimitsclass (Apex Limits Class)
Tooling API
An API for building…Tools
Tooling API Highlights
•  Gather finely grained metadata about Apex classes, triggers, and tests in an org
-  Classes, triggers, construction of symbol tables
-  Query for code coverage, logs, SOQL results
•  Query metadata about setup objects
-  Business processes, flows, custom items, workflow components
•  Can be utilized for source control/continuous integration
-  Metadata containers, deployment details, code file metadata
•  Can be queried through REST or SOAP
•  Similar to Metadata API but with a ton of additional functionality
​ Great for building…tools!
Our Scenario
​ UTILIZE DYNAMIC APEX TO WRITE APEX USING
APEX!
​ APEX-CEPTION!!!
Additional Tooling API Use Cases
•  Show all objects that can be analyzed
/services/data/v37.0/tooling/sobjects/
•  Show list of all classes
/services/data/v37.0/tooling/apexManifest
•  Show all metadata about a class
/services/data/v37.0/tooling/sobjects/ApexClass/01po0000004SL5b
Tools To Be Built
•  UML Diagram Tool
•  Symbol Table Visualizer
•  Automated Testing Tools
•  Tools to identify unused code
•  Customize managed packages based on
org’s config
•  Use your imagination!
Summary
Next Steps from Here
Summary and Next Steps
•  Be thinking about the right type of code for the app you’re building
•  Write dynamic code
•  Gather granular details to build any app
•  Get out there and build!
Where to Learn More
•  Follow @andyinthecloud (Andy Fawcett, CTO Financial Force)
•  Andy Fawcett’s Blog https://andyinthecloud.com/category/tooling-api/
•  Andy and James Loghry’s Apex Tooling API Wrapper:
https://github.com/afawcett/apex-toolingapi/
•  Pat Patterson’s Java Tooling API Wrapper: https://github.com/metadaddy/force-tooling-demo
https://developer.salesforce.com/blogs/developer-relations/2013/01/new-in-spring-13-the-
tooling-api.html
•  Tom Patros VF page Utilizing Symbol Tables:
https://github.com/tompatros/df13-tooling-api-demo and
http://www.redargyle.com/blog/tooling-around-tooling-api/
Thank Y u
Q&A

More Related Content

PDF
Write Generic Code with the Tooling API
PDF
Mocking APIs Collaboratively with Postman
PPTX
Scala & Swagger at Wordnik
PDF
REST vs. GraphQL: Critical Look
PDF
API Docs Made Right / RAML - Swagger rant
PPTX
Do's and Don'ts of APIs
PPTX
Api Design
PDF
apidays LIVE London 2021 - Consumer-first APIs in Open Banking by Chris Dudle...
Write Generic Code with the Tooling API
Mocking APIs Collaboratively with Postman
Scala & Swagger at Wordnik
REST vs. GraphQL: Critical Look
API Docs Made Right / RAML - Swagger rant
Do's and Don'ts of APIs
Api Design
apidays LIVE London 2021 - Consumer-first APIs in Open Banking by Chris Dudle...

What's hot (20)

PPTX
Pain Points In API Development? They’re Everywhere
PDF
Real-time GraphQL API with minimum coding and maximum benefit
PDF
London React August - GraphQL at The Financial Times - Viktor Charypar
PPTX
API-first development
PDF
apidays LIVE Hong Kong 2021 - GraphQL : Beyond APIs, graph your enterprise by...
PPTX
Continuous Integration and Delivery at Shapeways (Matt Boyle)
PDF
The Magic Behind Faster API Development, Testing and Delivery with API Virtua...
PDF
apidays LIVE Paris - The Augmented API Design Reviewer by Arnaud Lauret
PPTX
Huge: Running an API at Scale
PDF
apidays LIVE Paris 2021 - Learning the Language of HTTP for a Better Data Exp...
PDF
apidays LIVE Paris 2021 - Localizing OpenAPI Specification by Olga Baybakova,...
PDF
apidays LIVE London 2021 - Designing APIs: Less Data is More by Damir Svrtan,...
PDF
Introduction to GraphQL
PDF
GraphQL Munich Meetup #1 - How We Use GraphQL At Commercetools
PPTX
Api Design Anti-Patterns
PPTX
Tools and techniques for APIs
PDF
GraphQL Europe Recap
PPTX
Domain Driven Design Through Onion Architecture
PDF
Introduction to APIs, Integrations and Open Data
PDF
APEX Alpe Adria Mike Hichwa Keynote April 11th 2019- Zagreb
Pain Points In API Development? They’re Everywhere
Real-time GraphQL API with minimum coding and maximum benefit
London React August - GraphQL at The Financial Times - Viktor Charypar
API-first development
apidays LIVE Hong Kong 2021 - GraphQL : Beyond APIs, graph your enterprise by...
Continuous Integration and Delivery at Shapeways (Matt Boyle)
The Magic Behind Faster API Development, Testing and Delivery with API Virtua...
apidays LIVE Paris - The Augmented API Design Reviewer by Arnaud Lauret
Huge: Running an API at Scale
apidays LIVE Paris 2021 - Learning the Language of HTTP for a Better Data Exp...
apidays LIVE Paris 2021 - Localizing OpenAPI Specification by Olga Baybakova,...
apidays LIVE London 2021 - Designing APIs: Less Data is More by Damir Svrtan,...
Introduction to GraphQL
GraphQL Munich Meetup #1 - How We Use GraphQL At Commercetools
Api Design Anti-Patterns
Tools and techniques for APIs
GraphQL Europe Recap
Domain Driven Design Through Onion Architecture
Introduction to APIs, Integrations and Open Data
APEX Alpe Adria Mike Hichwa Keynote April 11th 2019- Zagreb
Ad

Viewers also liked (20)

PPTX
La mediación escolar_rosa_garcia_mendive
PDF
10 Economic Consequences of Trump
PPTX
عند بناء محتوى تسويقي... لا تتحدث مع الغرباء!
PPTX
Pancreatitis aguda y crónica
PPTX
Docker Online Meetup: Announcing Docker CE + EE
DOC
Plataformas y redes de comunicacion
PPT
Vertebrates and invertebrates
PPTX
3Com 70N3
PPTX
Hemorragia digestiva y síndrome pilórico
PDF
Región NOA
PDF
Investigación ATIT
PPT
Energy conversion
PDF
EVALUATION OF SCIENTIFIC ATTITUDE AMONG STUDENT TEACHERS
PDF
Build Features, Not Apps
DOCX
Artificial inteligence by m.shahbaz ..
PPTX
Presentación algoritmo
PPTX
Video Media
PPT
Presentació de la ponència.esc.coop.el puig
PDF
Exercício contabilidade débito e crédito
La mediación escolar_rosa_garcia_mendive
10 Economic Consequences of Trump
عند بناء محتوى تسويقي... لا تتحدث مع الغرباء!
Pancreatitis aguda y crónica
Docker Online Meetup: Announcing Docker CE + EE
Plataformas y redes de comunicacion
Vertebrates and invertebrates
3Com 70N3
Hemorragia digestiva y síndrome pilórico
Región NOA
Investigación ATIT
Energy conversion
EVALUATION OF SCIENTIFIC ATTITUDE AMONG STUDENT TEACHERS
Build Features, Not Apps
Artificial inteligence by m.shahbaz ..
Presentación algoritmo
Video Media
Presentació de la ponència.esc.coop.el puig
Exercício contabilidade débito e crédito
Ad

Similar to Punta Dreamin 17 Generic Apex and Tooling Api (20)

PDF
API Description Languages
PDF
API Description Languages
PDF
(ATS6-DEV02) Web Application Strategies
PPTX
PPTX
API workshop: Introduction to APIs (TC Camp)
PPTX
Create Salesforce online IDE in 30 minutes
PPTX
Lessons learned on the Azure API Stewardship Journey.pptx
PDF
API Description Languages: Which Is The Right One For Me?
PPTX
Design for scale
PDF
PDF
How to create custom dashboards in Elastic Search / Kibana with Performance V...
PPTX
API City 2019 Presentation - Delivering Developer Tools at Scale: Microsoft A...
PDF
SGCE 2015 REST APIs
PDF
APIs distribuidos con alta escalabilidad
DOC
Varun-CV-J
PDF
Practices and tools for building better APIs
PDF
Practices and tools for building better API (JFall 2013)
PDF
Lifecycle Management with SharePoint Apps and Solutions
PPTX
Sahi Principles and Architecture
PPTX
Scaling with swagger
API Description Languages
API Description Languages
(ATS6-DEV02) Web Application Strategies
API workshop: Introduction to APIs (TC Camp)
Create Salesforce online IDE in 30 minutes
Lessons learned on the Azure API Stewardship Journey.pptx
API Description Languages: Which Is The Right One For Me?
Design for scale
How to create custom dashboards in Elastic Search / Kibana with Performance V...
API City 2019 Presentation - Delivering Developer Tools at Scale: Microsoft A...
SGCE 2015 REST APIs
APIs distribuidos con alta escalabilidad
Varun-CV-J
Practices and tools for building better APIs
Practices and tools for building better API (JFall 2013)
Lifecycle Management with SharePoint Apps and Solutions
Sahi Principles and Architecture
Scaling with swagger

More from Adam Olshansky (7)

PPTX
Apex Testing Deep Dive
PDF
Maximize Apex Performance with Platform Cache
PDF
Lightning Components 101: An Apex Developer's Guide
PDF
Demystifying Code for Admins: The Last Step to Apex
PDF
Force Academy LA Trigger Framework
PDF
Blaze Your Trail
PDF
Phx User Group Salesforce Connect
Apex Testing Deep Dive
Maximize Apex Performance with Platform Cache
Lightning Components 101: An Apex Developer's Guide
Demystifying Code for Admins: The Last Step to Apex
Force Academy LA Trigger Framework
Blaze Your Trail
Phx User Group Salesforce Connect

Recently uploaded (20)

PDF
Advanced IT Governance
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
GamePlan Trading System Review: Professional Trader's Honest Take
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Big Data Technologies - Introduction.pptx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Electronic commerce courselecture one. Pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
Advanced IT Governance
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
GamePlan Trading System Review: Professional Trader's Honest Take
Network Security Unit 5.pdf for BCA BBA.
Big Data Technologies - Introduction.pptx
The Rise and Fall of 3GPP – Time for a Sabbatical?
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Reach Out and Touch Someone: Haptics and Empathic Computing
Electronic commerce courselecture one. Pdf
20250228 LYD VKU AI Blended-Learning.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
The AUB Centre for AI in Media Proposal.docx
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
NewMind AI Weekly Chronicles - August'25 Week I
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Review of recent advances in non-invasive hemoglobin estimation
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Mobile App Security Testing_ A Comprehensive Guide.pdf
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....

Punta Dreamin 17 Generic Apex and Tooling Api

  • 2. Writing Highly Genericized Code Using Dynamic Apex and the Tooling API Adam Olshansky Salesforce Developer, Contractor at YouTube Salesforce MVP, 13X Certified AdamToArchitect.com @adam17amo
  • 3. ¡Estoy feliz de estar en Punta del Este!
  • 4. Agenda •  Overview of generic code for Apex •  Dynamic Code in Salesforce •  Tooling API
  • 6. What problems are we solving for? •  Rigid or fragile code •  Poor Reusability •  Lots of patches/quick fixes •  Duplicate code •  Overly complicated data structures •  Maps of maps of maps…
  • 7. Who are we talking to today? •  ISV developers •  Don’t know all conditions of customer orgs •  Individual app developers •  May need to accept input from clients/customers •  Any developer accepting user input •  Tailor your queries and results based on user conditions
  • 8. Different Ways of Writing Code: Static vs. Dynamic Static •  Generated at compile time •  Hard coded •  Doesn’t usually have dependencies •  Works well if you know what’s in the org •  Most commonly used by developers at a company developing for their own org Dynamic/Generic •  Generated at run time •  Dependent on user input •  May have org-specific dependencies •  Works well if you DON’T know what’s in the org •  Most commonly used by developers whose code needs to run in customized orgs
  • 9. 2 Different Ways of Writing Code
  • 10. Tradeoffs ​ Positives •  More detailed information •  Less chance of an error down the road •  Endless possibilities ​ Negatives •  More code to write •  More code to test •  Less readability
  • 11. Tools of the Trade
  • 12. Several Ways in Salesforce •  Custom Settings/Metadata •  Dynamic Apex •  Dynamic Visualforce •  Dynamic SOQL •  Limits class •  Schema class
  • 16. Dynamic SOQL •  Don’t always know what parameters are available in a user’s org •  In your org this will work •  What if your customer doesn’t have record types defined for Lead?
  • 17. Limits Class •  Limits.getDMLRows(); •  Limits.getDMLStatements(); •  Limits.getHeapSize(); •  Limits.getQueries(); •  Limits.getQueryRows(); •  bit.ly/apexlimitsclass (Apex Limits Class)
  • 18. Tooling API An API for building…Tools
  • 19. Tooling API Highlights •  Gather finely grained metadata about Apex classes, triggers, and tests in an org -  Classes, triggers, construction of symbol tables -  Query for code coverage, logs, SOQL results •  Query metadata about setup objects -  Business processes, flows, custom items, workflow components •  Can be utilized for source control/continuous integration -  Metadata containers, deployment details, code file metadata •  Can be queried through REST or SOAP •  Similar to Metadata API but with a ton of additional functionality ​ Great for building…tools!
  • 20. Our Scenario ​ UTILIZE DYNAMIC APEX TO WRITE APEX USING APEX! ​ APEX-CEPTION!!!
  • 21. Additional Tooling API Use Cases •  Show all objects that can be analyzed /services/data/v37.0/tooling/sobjects/ •  Show list of all classes /services/data/v37.0/tooling/apexManifest •  Show all metadata about a class /services/data/v37.0/tooling/sobjects/ApexClass/01po0000004SL5b
  • 22. Tools To Be Built •  UML Diagram Tool •  Symbol Table Visualizer •  Automated Testing Tools •  Tools to identify unused code •  Customize managed packages based on org’s config •  Use your imagination!
  • 24. Summary and Next Steps •  Be thinking about the right type of code for the app you’re building •  Write dynamic code •  Gather granular details to build any app •  Get out there and build!
  • 25. Where to Learn More •  Follow @andyinthecloud (Andy Fawcett, CTO Financial Force) •  Andy Fawcett’s Blog https://andyinthecloud.com/category/tooling-api/ •  Andy and James Loghry’s Apex Tooling API Wrapper: https://github.com/afawcett/apex-toolingapi/ •  Pat Patterson’s Java Tooling API Wrapper: https://github.com/metadaddy/force-tooling-demo https://developer.salesforce.com/blogs/developer-relations/2013/01/new-in-spring-13-the- tooling-api.html •  Tom Patros VF page Utilizing Symbol Tables: https://github.com/tompatros/df13-tooling-api-demo and http://www.redargyle.com/blog/tooling-around-tooling-api/
  • 27. Q&A