SlideShare a Scribd company logo
Fun with Generic SObjects
​ Evan Kennedy
​ Senior Salesforce Developer/Technical Architect
​ evan@modacto.com
Writing code to work against any Salesforce object.
Evan Kennedy
Senior Salesforce Developer/Technical Architect
About Modacto
​ Implementation and optimization of the Salesforce platform for growth-minded
organizations.
•  Improvements
•  Meaningful
business value
•  Effective support
of Salesforce
ecosystem
•  Cleansing,
migration,
integration
•  Reporting and
dashboards
•  Lightning connect
•  Wave
​ Ready to go
Modacto?
​ 800 Washington Ave
N
Suite 907
Minneapolis, MN
55401
​ 612.200.0846
info@modacto.com
•  Going beyond
configuration
•  Customized app
builds
•  Comfortable
adoption
Overview of Topic
​ We all like to write re-usable code, one of the ways to do this is to use Generic
SObjects in our Apex classes.
​  Some code examples
•  Schema Describe Code
•  Multi-Object Trigger Handlers
•  Apex REST endpoint for generic SObjects
•  Crud Enforcement
​  A couple of real-world case studies
​  Pros and common pitfalls of generic SObjects
Code Examples
Let’s just jump right in, shall we?
Example 1
Using the Schema Describe Code, Dynamic SOQL
Schema Describe Code and Dynamic SOQL
​ This example will cover:
•  Using the Schema describe code to get object and field information in Apex.
•  Using this information to construct dynamic SOQL queries.
Example 2
Multi-Object Trigger Handlers
​ In this example we’re going to look at:
•  Writing simple trigger handler code to handle multiple types of objects
•  Retrieving field data from a generic SObject.
Multi-Object Trigger Handlers
Example 3
Apex REST Endpoint for Lists of Generic SObjects
​ Useful when needing to implement additional endpoint logic across many objects.
​ Good for Salesforce to Salesforce types of custom integrations.
Apex REST Endpoint for Generic SObjects
Example 4
Small examples: Crud Enforcement and Object Sorting
​ Required for AppExchange security review
​ Good way to enforce profile/permission set object and field-level security.
​ Existing Package for this: https://github.com/ZergyPoo/SFDCCrudEnforcementUtils
Crud Enforcement
​ Custom SObject Sorting where SOQL falls short.
​ Good for fields that contain numbers and text.
SObject Sorting
Real-World Case Studies
PromotionBuilder and Solomon365
​ PromotionBuilder
•  Gamification app
•  Allows users to setup custom criteria against any
of their objects
•  Runs the same trigger code against the objects to
check for gamification criteria.
​ Solomon365
•  Hub and Spoke model
•  Data syncing back from the spokes to the hub
organization
•  Needed custom Apex REST endpoints to handle
multiple types of objects with complex logic
without having to duplicate code.
Cool Real-World Examples
The Good and the Bad
Pros and Common Pitfalls of using Generic SObjects
​ Pros – What is great about using generic
SObjects
•  Lots of re-usable code
•  Covering common functionality without have to
copy and paste all the time
•  Great for apps, lets your clients run your code
against their own custom objects
•  Dynamic SOQL
​ Cons – The ugly
•  Much more prone to run-time error
•  Can be more confusing to read the code
•  Object instantiation can get a little wonky
Pros and Cons
It’s a Wrap!
​ Pros and Cons of using generic SObjects in Apex code.
​ Some awesome code examples
​ Some Real-world applications
What did we cover?
Wrap-Up
Any Questions?
​ Feel free to ask me anything (within reason)
Thank you

More Related Content

PDF
Understanding the Salesforce Architecture: How We Do the Magic We Do
PPTX
Understanding Multitenancy and the Architecture of the Salesforce Platform
PPTX
"How do I Architect?" - Quick Introduction to Architecture for Salesforce Ad...
PDF
Use Custom Metadata Types for Easy ALM & Compliance for Your Custom Apps
PPTX
Salesforce Cloud Infrastructure and Challenges - A Brief Overview
PPTX
Salesforce Multitenant Architecture: How We Do the Magic We Do
PDF
Salesforce1: Every Developer is a Mobile Developer
PDF
Best Practices for Team Development in a Single Org
Understanding the Salesforce Architecture: How We Do the Magic We Do
Understanding Multitenancy and the Architecture of the Salesforce Platform
"How do I Architect?" - Quick Introduction to Architecture for Salesforce Ad...
Use Custom Metadata Types for Easy ALM & Compliance for Your Custom Apps
Salesforce Cloud Infrastructure and Challenges - A Brief Overview
Salesforce Multitenant Architecture: How We Do the Magic We Do
Salesforce1: Every Developer is a Mobile Developer
Best Practices for Team Development in a Single Org

What's hot (20)

PPTX
Salesforce Consulting Services
PPTX
Coding Apps in the Cloud with Force.com - Part 2
PPTX
Integrating Salesforce with Microsoft Office through Add-ins
PPT
How Salesforce.com R&D Delivers the Cloud
PDF
App to AppExchange - A Journey from Idea to Market for Salesforce Developers
PPTX
Building BOTS on App Cloud
PDF
Let's Learn About Heroku and How to Integrate with Salesforce
PDF
Salesforce DX Pilot Product Overview
PDF
How Salesforce.com R&D Delivers the Cloud
PPTX
Salesforce integration best practices columbus meetup
PDF
Enterprise Integration - Solution Patterns From the Field
PDF
Utilize Heroku to Push Google Analytics Data into Analytics Cloud
PDF
Introduction to MuleSoft
PDF
Beyond Custom Metadata Types
PDF
Manage Massive Datasets with Big Objects & Async SOQL
PDF
Integrating SIS’s with Salesforce: An Accidental Integrator’s Guide
PDF
Manage Development in Your Org with Salesforce Governance Framework
PDF
UX and Design: Top Tips for Salesforce Apps on Mobile and Wearables
PPT
The Importance of Integration to Salesforce Success
PDF
Two-Way Integration with Writable External Objects
Salesforce Consulting Services
Coding Apps in the Cloud with Force.com - Part 2
Integrating Salesforce with Microsoft Office through Add-ins
How Salesforce.com R&D Delivers the Cloud
App to AppExchange - A Journey from Idea to Market for Salesforce Developers
Building BOTS on App Cloud
Let's Learn About Heroku and How to Integrate with Salesforce
Salesforce DX Pilot Product Overview
How Salesforce.com R&D Delivers the Cloud
Salesforce integration best practices columbus meetup
Enterprise Integration - Solution Patterns From the Field
Utilize Heroku to Push Google Analytics Data into Analytics Cloud
Introduction to MuleSoft
Beyond Custom Metadata Types
Manage Massive Datasets with Big Objects & Async SOQL
Integrating SIS’s with Salesforce: An Accidental Integrator’s Guide
Manage Development in Your Org with Salesforce Governance Framework
UX and Design: Top Tips for Salesforce Apps on Mobile and Wearables
The Importance of Integration to Salesforce Success
Two-Way Integration with Writable External Objects
Ad

Viewers also liked (20)

PDF
Confessions of a Technical Writer
PDF
Erin Vang - Rockstars, not typists! Expanding your influence in tech organiza...
PDF
No Boring Content Allowed!
PPTX
Judges training m wright food and nutrition 2013
PDF
GetBadges - gamification platform for software developers
PPT
What every teacher should know about cognitive science
PDF
PDF
MAGIC of the twitisphere.... Making the writing programme fun
PPTX
Village workshop - Tech Ideas to Make Writing Fun
PDF
ADVERGAME, quand la marque se met au jeu
PPTX
How Cognitive Science Can Help You Through School
PDF
Gamification: Make Freelance Writing More Fun
PDF
Monika Konieczny - Gamification & storytelling: how to turn boring technical ...
PDF
Communication with Flexible Documentation : Jon Hadden
PPTX
Present day english
PPTX
This is Your Brain on Content: Cognitive Science Lessons for Content Strategy
PDF
Fun at work through innovation games
PPTX
12 Secrets of Making Every Presentation Fun, Engaging and Enjoyable
PPT
Qualities of good technical writing with examples
PPTX
Technical Writing
Confessions of a Technical Writer
Erin Vang - Rockstars, not typists! Expanding your influence in tech organiza...
No Boring Content Allowed!
Judges training m wright food and nutrition 2013
GetBadges - gamification platform for software developers
What every teacher should know about cognitive science
MAGIC of the twitisphere.... Making the writing programme fun
Village workshop - Tech Ideas to Make Writing Fun
ADVERGAME, quand la marque se met au jeu
How Cognitive Science Can Help You Through School
Gamification: Make Freelance Writing More Fun
Monika Konieczny - Gamification & storytelling: how to turn boring technical ...
Communication with Flexible Documentation : Jon Hadden
Present day english
This is Your Brain on Content: Cognitive Science Lessons for Content Strategy
Fun at work through innovation games
12 Secrets of Making Every Presentation Fun, Engaging and Enjoyable
Qualities of good technical writing with examples
Technical Writing
Ad

Similar to Writing Code to Work Against any Salesforce Object (20)

PPTX
Polaris presentation ioc - code conference
PDF
Sitecore development approach evolution – destination helix
PPTX
jForce In Action
PPTX
IBM Developer Model Asset eXchange - Deep Learning for Everyone
PPTX
Xamarin.Forms Bootcamp
PDF
Mobx Internals
PDF
NetWork - 15.10.2011 - Applied code generation in .NET
PPTX
Developing with Sitecore Personalize SDK.pptx
DOC
Subhasis Java Resume
PDF
What Web Framework To Use?
PDF
Punta Dreamin 17 Generic Apex and Tooling Api
PDF
Fed London - January 2015
PDF
Apex Enterprise Patterns Galore - Boston, MA dev group meeting 062719
PDF
Pluggable patterns
PPT
SDWest2005Goetsch
PPTX
Intro to Salesforce Lightning Web Components (LWC)
PDF
springtraning-7024840-phpapp01.pdf
PPTX
Recurrent Neural Network : Multi-Class & Multi Label Text Classification
PDF
Click, Click, Test - Automated Tests for APEX Applications
PDF
selenium_course_content.pdf
Polaris presentation ioc - code conference
Sitecore development approach evolution – destination helix
jForce In Action
IBM Developer Model Asset eXchange - Deep Learning for Everyone
Xamarin.Forms Bootcamp
Mobx Internals
NetWork - 15.10.2011 - Applied code generation in .NET
Developing with Sitecore Personalize SDK.pptx
Subhasis Java Resume
What Web Framework To Use?
Punta Dreamin 17 Generic Apex and Tooling Api
Fed London - January 2015
Apex Enterprise Patterns Galore - Boston, MA dev group meeting 062719
Pluggable patterns
SDWest2005Goetsch
Intro to Salesforce Lightning Web Components (LWC)
springtraning-7024840-phpapp01.pdf
Recurrent Neural Network : Multi-Class & Multi Label Text Classification
Click, Click, Test - Automated Tests for APEX Applications
selenium_course_content.pdf

More from Salesforce Developers (20)

PDF
Sample Gallery: Reference Code and Best Practices for Salesforce Developers
PDF
Maximizing Salesforce Lightning Experience and Lightning Component Performance
PDF
Local development with Open Source Base Components
PPTX
TrailheaDX India : Developer Highlights
PDF
Why developers shouldn’t miss TrailheaDX India
PPTX
CodeLive: Build Lightning Web Components faster with Local Development
PPTX
CodeLive: Converting Aura Components to Lightning Web Components
PPTX
Enterprise-grade UI with open source Lightning Web Components
PPTX
TrailheaDX and Summer '19: Developer Highlights
PDF
Live coding with LWC
PDF
Lightning web components - Episode 4 : Security and Testing
PDF
LWC Episode 3- Component Communication and Aura Interoperability
PDF
Lightning web components episode 2- work with salesforce data
PDF
Lightning web components - Episode 1 - An Introduction
PDF
Migrating CPQ to Advanced Calculator and JSQCP
PDF
Scale with Large Data Volumes and Big Objects in Salesforce
PDF
Replicate Salesforce Data in Real Time with Change Data Capture
PDF
Modern Development with Salesforce DX
PDF
Get Into Lightning Flow Development
PDF
Integrate CMS Content Into Lightning Communities with CMS Connect
Sample Gallery: Reference Code and Best Practices for Salesforce Developers
Maximizing Salesforce Lightning Experience and Lightning Component Performance
Local development with Open Source Base Components
TrailheaDX India : Developer Highlights
Why developers shouldn’t miss TrailheaDX India
CodeLive: Build Lightning Web Components faster with Local Development
CodeLive: Converting Aura Components to Lightning Web Components
Enterprise-grade UI with open source Lightning Web Components
TrailheaDX and Summer '19: Developer Highlights
Live coding with LWC
Lightning web components - Episode 4 : Security and Testing
LWC Episode 3- Component Communication and Aura Interoperability
Lightning web components episode 2- work with salesforce data
Lightning web components - Episode 1 - An Introduction
Migrating CPQ to Advanced Calculator and JSQCP
Scale with Large Data Volumes and Big Objects in Salesforce
Replicate Salesforce Data in Real Time with Change Data Capture
Modern Development with Salesforce DX
Get Into Lightning Flow Development
Integrate CMS Content Into Lightning Communities with CMS Connect

Recently uploaded (20)

PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Electronic commerce courselecture one. Pdf
PPTX
Cloud computing and distributed systems.
PPT
Teaching material agriculture food technology
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Approach and Philosophy of On baking technology
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
cuic standard and advanced reporting.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
KodekX | Application Modernization Development
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
NewMind AI Weekly Chronicles - August'25 Week I
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Electronic commerce courselecture one. Pdf
Cloud computing and distributed systems.
Teaching material agriculture food technology
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Approach and Philosophy of On baking technology
Network Security Unit 5.pdf for BCA BBA.
Agricultural_Statistics_at_a_Glance_2022_0.pdf
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
cuic standard and advanced reporting.pdf
MYSQL Presentation for SQL database connectivity
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
KodekX | Application Modernization Development
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
NewMind AI Monthly Chronicles - July 2025
Review of recent advances in non-invasive hemoglobin estimation
Reach Out and Touch Someone: Haptics and Empathic Computing
Spectral efficient network and resource selection model in 5G networks
Build a system with the filesystem maintained by OSTree @ COSCUP 2025

Writing Code to Work Against any Salesforce Object

  • 1. Fun with Generic SObjects ​ Evan Kennedy ​ Senior Salesforce Developer/Technical Architect ​ evan@modacto.com Writing code to work against any Salesforce object.
  • 2. Evan Kennedy Senior Salesforce Developer/Technical Architect
  • 3. About Modacto ​ Implementation and optimization of the Salesforce platform for growth-minded organizations. •  Improvements •  Meaningful business value •  Effective support of Salesforce ecosystem •  Cleansing, migration, integration •  Reporting and dashboards •  Lightning connect •  Wave ​ Ready to go Modacto? ​ 800 Washington Ave N Suite 907 Minneapolis, MN 55401 ​ 612.200.0846 info@modacto.com •  Going beyond configuration •  Customized app builds •  Comfortable adoption
  • 4. Overview of Topic ​ We all like to write re-usable code, one of the ways to do this is to use Generic SObjects in our Apex classes. ​  Some code examples •  Schema Describe Code •  Multi-Object Trigger Handlers •  Apex REST endpoint for generic SObjects •  Crud Enforcement ​  A couple of real-world case studies ​  Pros and common pitfalls of generic SObjects
  • 5. Code Examples Let’s just jump right in, shall we?
  • 6. Example 1 Using the Schema Describe Code, Dynamic SOQL
  • 7. Schema Describe Code and Dynamic SOQL ​ This example will cover: •  Using the Schema describe code to get object and field information in Apex. •  Using this information to construct dynamic SOQL queries.
  • 9. ​ In this example we’re going to look at: •  Writing simple trigger handler code to handle multiple types of objects •  Retrieving field data from a generic SObject. Multi-Object Trigger Handlers
  • 10. Example 3 Apex REST Endpoint for Lists of Generic SObjects
  • 11. ​ Useful when needing to implement additional endpoint logic across many objects. ​ Good for Salesforce to Salesforce types of custom integrations. Apex REST Endpoint for Generic SObjects
  • 12. Example 4 Small examples: Crud Enforcement and Object Sorting
  • 13. ​ Required for AppExchange security review ​ Good way to enforce profile/permission set object and field-level security. ​ Existing Package for this: https://github.com/ZergyPoo/SFDCCrudEnforcementUtils Crud Enforcement
  • 14. ​ Custom SObject Sorting where SOQL falls short. ​ Good for fields that contain numbers and text. SObject Sorting
  • 16. ​ PromotionBuilder •  Gamification app •  Allows users to setup custom criteria against any of their objects •  Runs the same trigger code against the objects to check for gamification criteria. ​ Solomon365 •  Hub and Spoke model •  Data syncing back from the spokes to the hub organization •  Needed custom Apex REST endpoints to handle multiple types of objects with complex logic without having to duplicate code. Cool Real-World Examples
  • 17. The Good and the Bad Pros and Common Pitfalls of using Generic SObjects
  • 18. ​ Pros – What is great about using generic SObjects •  Lots of re-usable code •  Covering common functionality without have to copy and paste all the time •  Great for apps, lets your clients run your code against their own custom objects •  Dynamic SOQL ​ Cons – The ugly •  Much more prone to run-time error •  Can be more confusing to read the code •  Object instantiation can get a little wonky Pros and Cons
  • 20. ​ Pros and Cons of using generic SObjects in Apex code. ​ Some awesome code examples ​ Some Real-world applications What did we cover? Wrap-Up
  • 21. Any Questions? ​ Feel free to ask me anything (within reason)