Upload
salesforce-developers
View
297
Download
1
Embed Size (px)
Citation preview
Fun with Generic SObjects
Evan Kennedy Senior Salesforce Developer/Technical Architect [email protected]
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 [email protected]
• 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