SlideShare a Scribd company logo
Adam Olshansky
Salesforce Developer,
Salesforce MVP
AdamToArchitect.com
@adam17amo
Writing Highly Genericized Code
Using Dynamic Apex and the
Tooling API
Adam Olshansky
Salesforce Developer, YouTube
@adam17amo
AdamToArchitect.com
NAMASTE
THANK YOU FOR INVITING
ME TO INDIA!
NAMASTE
Thank you to dQuotient for
sponsoring!
Agenda
• An overview of Generic code for Apex
• Salesforce Dynamic Coding Examples
• Tooling API
Generic Programming in Apex
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
What problem are we solving for?
● Rigid/Fragile
● Poor (Re)usability
● Lots of patches/quick fixes
● Duplicate code
● Overly complicated data structures
○ Maps of Maps of Maps of…..
○ Managing the data in a 5-D Arrays
2 Different Ways of Writing Code
​Static
​Dynamic/Generic
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
Tradeoffs of Dynamic Coding
Negatives
• More code to write
• More code to test
• Less readabillity
Positives
• More detailed information
• Less chance of an error down the road
• Endless possibilities
Dynamic Coding Examples
Tools of the trade
● Custom Settings/Metadata
● Schema class
● Dynamic Apex
● Dynamic Visualforce
● Dynamic SOQL
● Limits class
Dynamic Apex (Metadata)
Dynamic Apex (Data)
Dynamic Controller
Dynamic Visualforce
Dynamic SOQL
• Don’t always know what parameters are available in a user’s org
• In your org this works fine
Database.query()
Thanks to Dan Appleman, Advanced Apex Programming
• 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)
Dynamically make adjustments based on limits
Tying it Together
● You know how to design apps efficiently
● You know how to write generic code
● You know how to find information about org metadata
● What’s next?
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!
Tooling API Examples
Create a class
https://andyinthecloud.com/category/tooling-api/
Additional Tooling API Use Cases
https://andyinthecloud.com/category/tooling-api/
• Show all objects that can be analyzed
• /services/data/v39.0/tooling/sobjects/
• Show list of all classes
• /services/data/v39.0/tooling/apexManifest
• Show all metadata about a class
• /services/data/v39.0/tooling/sobjects/ApexClass/01po0000004SL5b
Another Scenario
UTILIZE DYNAMIC APEX TO WRITE APEX USING APEX!
APEX-CEPTION!!!
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
• Utilize design patterns
• Write dynamic code
• Gather granular details to build any app
• Get out there and build!
Where to Learn More
● Follow @andyinthecloud and his blog!
● 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-too
ling-api.html
● Tom Patros VF page Utilizing Symbol Tables (The Documenter):
https://github.com/tompatros/df13-tooling-api-demo
Thank Y u

More Related Content

What's hot (20)

PDF
GraphQL Munich Meetup #1 - How We Use GraphQL At Commercetools
Nicola Molinari
 
DOC
Varun-CV-J
Varun Goswami
 
PDF
GraphQL Europe Recap
Philipp Sporrer
 
PDF
apidays LIVE Paris 2021 - Localizing OpenAPI Specification by Olga Baybakova,...
apidays
 
PDF
Wrapping and Securing REST APIs with GraphQL
Roy Derks
 
PPTX
Salesforce Apex Hours : How Lightning Platform Query Optimizer works for LDV
Amit Chaudhary
 
PDF
apidays LIVE London 2021 - Consumer-first APIs in Open Banking by Chris Dudle...
apidays
 
PPTX
Using RAML 1.0 Like a Pro
MuleSoft
 
PDF
Creating a Business Oriented UI in APEX
Enkitec
 
DOC
Sanjeev rai
Sanjeev Kumar Rai
 
PPTX
GraphQL - Missing Link In REST
Anubolu Sreekanth
 
PDF
apidays LIVE London 2021 - Designing APIs: Less Data is More by Damir Svrtan,...
apidays
 
PDF
Salesforce Certifications:Explained
Atul Gupta(8X)
 
PDF
APEX 5 Interactive Reports: Deep Dive and Upgrade Advice
Karen Cannell
 
PPTX
Episode 2 conditional flows & loops
Jitendra Zaa
 
ODP
Domain Driven design
Alireza Rahmani Khalili
 
PDF
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
Gavin Pickin
 
PDF
Introduction to APIs, Integrations and Open Data
Resolver Inc.
 
PPTX
Ladies Be Architects - Apex Basics
gemziebeth
 
PPTX
API-first development
Vasco Veloso
 
GraphQL Munich Meetup #1 - How We Use GraphQL At Commercetools
Nicola Molinari
 
Varun-CV-J
Varun Goswami
 
GraphQL Europe Recap
Philipp Sporrer
 
apidays LIVE Paris 2021 - Localizing OpenAPI Specification by Olga Baybakova,...
apidays
 
Wrapping and Securing REST APIs with GraphQL
Roy Derks
 
Salesforce Apex Hours : How Lightning Platform Query Optimizer works for LDV
Amit Chaudhary
 
apidays LIVE London 2021 - Consumer-first APIs in Open Banking by Chris Dudle...
apidays
 
Using RAML 1.0 Like a Pro
MuleSoft
 
Creating a Business Oriented UI in APEX
Enkitec
 
Sanjeev rai
Sanjeev Kumar Rai
 
GraphQL - Missing Link In REST
Anubolu Sreekanth
 
apidays LIVE London 2021 - Designing APIs: Less Data is More by Damir Svrtan,...
apidays
 
Salesforce Certifications:Explained
Atul Gupta(8X)
 
APEX 5 Interactive Reports: Deep Dive and Upgrade Advice
Karen Cannell
 
Episode 2 conditional flows & loops
Jitendra Zaa
 
Domain Driven design
Alireza Rahmani Khalili
 
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
Gavin Pickin
 
Introduction to APIs, Integrations and Open Data
Resolver Inc.
 
Ladies Be Architects - Apex Basics
gemziebeth
 
API-first development
Vasco Veloso
 

Similar to Write Generic Code with the Tooling API (20)

PDF
Single Source of Truth for Network Automation
Andy Davidson
 
PDF
Proud to be polyglot
Tugdual Grall
 
PDF
API Description Languages
Akana
 
PDF
API Description Languages
Akana
 
PDF
(ATS6-DEV02) Web Application Strategies
BIOVIA
 
PPTX
Basic Application Performance Optimization Techniques (Backend)
Klas Berlič Fras
 
PDF
APIs and SDKs: Breaking into and Succeeding in a Specialty Market
STC-Philadelphia Metro Chapter
 
PDF
How To Use Selenium Successfully
Dave Haeffner
 
PDF
Practices and tools for building better API (JFall 2013)
Peter Hendriks
 
PDF
Practices and tools for building better APIs
NLJUG
 
PPTX
JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...
Speedment, Inc.
 
PPTX
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
Malin Weiss
 
PDF
The Characteristics of a Successful SPA
Gil Fink
 
PPTX
Practices and Tools for Building Better APIs
Peter Hendriks
 
PDF
Presentacion day f-core v1.2.1.2-technical - english
Jose Luis Sanchez del Coso
 
PDF
How to create custom dashboards in Elastic Search / Kibana with Performance V...
PerformanceVision (previously SecurActive)
 
PPTX
API workshop: Introduction to APIs (TC Camp)
Tom Johnson
 
PPTX
API ARU-ARU
CData Software Japan
 
PDF
APIs and SDKs: Breaking Into and Succeeding in a Specialty Market
Scott Abel
 
PDF
Five Ways to Scale your API Without Touching Your Code
3scale
 
Single Source of Truth for Network Automation
Andy Davidson
 
Proud to be polyglot
Tugdual Grall
 
API Description Languages
Akana
 
API Description Languages
Akana
 
(ATS6-DEV02) Web Application Strategies
BIOVIA
 
Basic Application Performance Optimization Techniques (Backend)
Klas Berlič Fras
 
APIs and SDKs: Breaking into and Succeeding in a Specialty Market
STC-Philadelphia Metro Chapter
 
How To Use Selenium Successfully
Dave Haeffner
 
Practices and tools for building better API (JFall 2013)
Peter Hendriks
 
Practices and tools for building better APIs
NLJUG
 
JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...
Speedment, Inc.
 
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
Malin Weiss
 
The Characteristics of a Successful SPA
Gil Fink
 
Practices and Tools for Building Better APIs
Peter Hendriks
 
Presentacion day f-core v1.2.1.2-technical - english
Jose Luis Sanchez del Coso
 
How to create custom dashboards in Elastic Search / Kibana with Performance V...
PerformanceVision (previously SecurActive)
 
API workshop: Introduction to APIs (TC Camp)
Tom Johnson
 
APIs and SDKs: Breaking Into and Succeeding in a Specialty Market
Scott Abel
 
Five Ways to Scale your API Without Touching Your Code
3scale
 
Ad

More from Adam Olshansky (7)

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

Recently uploaded (20)

PPTX
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
PDF
Streamline Contractor Lifecycle- TECH EHS Solution
TECH EHS Solution
 
PDF
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
PDF
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
PDF
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
DOCX
Import Data Form Excel to Tally Services
Tally xperts
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
PDF
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
PDF
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
PPTX
3uTools Full Crack Free Version Download [Latest] 2025
muhammadgurbazkhan
 
PDF
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
PPTX
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
PDF
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
PPT
MergeSortfbsjbjsfk sdfik k
RafishaikIT02044
 
PPTX
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
PDF
Salesforce CRM Services.VALiNTRY360
VALiNTRY360
 
PPTX
Feb 2021 Cohesity first pitch presentation.pptx
enginsayin1
 
PPTX
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
PDF
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
Streamline Contractor Lifecycle- TECH EHS Solution
TECH EHS Solution
 
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
Import Data Form Excel to Tally Services
Tally xperts
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
3uTools Full Crack Free Version Download [Latest] 2025
muhammadgurbazkhan
 
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
MergeSortfbsjbjsfk sdfik k
RafishaikIT02044
 
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
Salesforce CRM Services.VALiNTRY360
VALiNTRY360
 
Feb 2021 Cohesity first pitch presentation.pptx
enginsayin1
 
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 

Write Generic Code with the Tooling API

  • 1. Adam Olshansky Salesforce Developer, Salesforce MVP AdamToArchitect.com @adam17amo Writing Highly Genericized Code Using Dynamic Apex and the Tooling API
  • 2. Adam Olshansky Salesforce Developer, YouTube @adam17amo AdamToArchitect.com
  • 3. NAMASTE THANK YOU FOR INVITING ME TO INDIA!
  • 4. NAMASTE Thank you to dQuotient for sponsoring!
  • 5. Agenda • An overview of Generic code for Apex • Salesforce Dynamic Coding Examples • Tooling API
  • 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. What problem are we solving for? ● Rigid/Fragile ● Poor (Re)usability ● Lots of patches/quick fixes ● Duplicate code ● Overly complicated data structures ○ Maps of Maps of Maps of….. ○ Managing the data in a 5-D Arrays
  • 9. 2 Different Ways of Writing Code ​Static ​Dynamic/Generic
  • 10. 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
  • 11. Tradeoffs of Dynamic Coding Negatives • More code to write • More code to test • Less readabillity Positives • More detailed information • Less chance of an error down the road • Endless possibilities
  • 13. Tools of the trade ● Custom Settings/Metadata ● Schema class ● Dynamic Apex ● Dynamic Visualforce ● Dynamic SOQL ● Limits class
  • 18. Dynamic SOQL • Don’t always know what parameters are available in a user’s org • In your org this works fine Database.query() Thanks to Dan Appleman, Advanced Apex Programming • What if your customer doesn’t have record types defined for Lead
  • 19. Limits Class • Limits.getDMLRows(); • Limits.getDMLStatements(); • Limits.getHeapSize(); • Limits.getQueries(); • Limits.getQueryRows(); • bit.ly/apexlimitsclass (Apex Limits Class) Dynamically make adjustments based on limits
  • 20. Tying it Together ● You know how to design apps efficiently ● You know how to write generic code ● You know how to find information about org metadata ● What’s next?
  • 21. Tooling API An API for building...TOOLS
  • 22. 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!
  • 23. Tooling API Examples Create a class https://andyinthecloud.com/category/tooling-api/
  • 24. Additional Tooling API Use Cases https://andyinthecloud.com/category/tooling-api/ • Show all objects that can be analyzed • /services/data/v39.0/tooling/sobjects/ • Show list of all classes • /services/data/v39.0/tooling/apexManifest • Show all metadata about a class • /services/data/v39.0/tooling/sobjects/ApexClass/01po0000004SL5b
  • 25. Another Scenario UTILIZE DYNAMIC APEX TO WRITE APEX USING APEX! APEX-CEPTION!!!
  • 26. 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!
  • 28. Summary and Next Steps • Be thinking about the right type of code for the app you’re building • Utilize design patterns • Write dynamic code • Gather granular details to build any app • Get out there and build!
  • 29. Where to Learn More ● Follow @andyinthecloud and his blog! ● 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-too ling-api.html ● Tom Patros VF page Utilizing Symbol Tables (The Documenter): https://github.com/tompatros/df13-tooling-api-demo