ºÝºÝߣs from Dreamforce 2015 session
Join us as we teach you how to create a set of versioned RESTful APIs by utilizing custom-settings and advanced Apex features such as Type and Schema. Via dynamic binding, the custom-APIs support multiple versions simultaneously, allowing a new version to be deployed without affecting existing API consumers. You will learn about how to use these advanced features in Apex.
code is available on https://github.com/erichpleung/dynamic-apex
1 of 24
Download to read offline
More Related Content
DF15 - Dynamic Apex Binding with design patterns
1. Dynamic Apex Binding
Eric Leung
Salesforce Solution Architect
eric.leung@fronde.com
@erichpleung
With Design Patterns
Ben Naylor
Senior Salesforce Technical Consultant
ben.naylor@fronde.com
@nzchicken
3. 8 Years
Salesforce Partnership
5 Locations
Wellington, Auckland, Sydney,
Melbourne, Manila
400+
Customers
23 Years
Experience in IT Solutions
Google
Enterprise Partner of the Year
2012, Australia and New Zealand
Amazon
Advanced Consulting Partner &
Channel Reseller Partner
300+
Hobbits/Roos
Salesforce
Platinum Partner
www.fronde.com
5. Agenda
Part 1: Design Patterns
? Factory and Proxy Patterns
Part 2: Custom Settings and Schema Namespace
Part 3: Dynamic Binding
6. What are Design Patterns?
Object Oriented Software Design
Commonly used in Object Oriented Languages
? Apex, Java, C#, Objective C
Reusable Solution Templates
? Not libraries
3 categories (from GoF)
? Creational ¨C object creation
? Structural ¨C relationships between objects
? Behavioural ¨C communication between objects
12. Store KVP
Application/Code Settings
List/Map containers
.getAll()
List vs. Hierarchy Custom Settings
User/Profile based
Global setting
One set of results
.getInstance()
List Type Hierarchy Type
16. What is Dynamic Binding?
Compile-time vs Runtime
Tightly coupled vs. Loosely coupled
Classes vs. Interfaces
Types vs. Objects
17. System.Type Class
System.Type.forName(className: String)
Default constructor
Type casting, can be interface
Dependency Injection
public interface Animal {...}
public class Cat implements Animal {
public Cat(){¡}// default constructor
}
System.Type sType = System.Type.forName('Cat'); // using apex-class name to get aType
Animal animal = (Animal) sType.newInstance(); // instantiate and cast to an interface
18. Back to the first demo¡
Boilerplate code
Not easy to add a new version
? New code: service, & implementation classes
? Need to update permissions on new classes
Testing predefined scenarios
? Testing compile time logic
Problems Changes
Using custom settings to provide
implementation details
Using System.Type to instantiate
implementation
Using classes in Schema namespaces to
create and query Salesforce objects
Testing runtime behaviour
? Setup test configuration
20. Summary
Dynamic Binding using Apex
? Runtime, Interfaces, Loosely Coupled
Custom Settings
? Hierarchical and List
Advance Apex Features
? System.Type and SObject classes
? Schema Namespace
21. Summary continues
Testing
? Interface driven
? Test classes can be used in custom setting
? Testing new scenarios
Other examples on using dynamic binding
? Fine grain security
? Extends Salesforce OOTB functions/features
? Trigger
22. References
Books:
? Design Patterns: Elements of Reusable Object-Oriented Software, Addison-Wesley
? Head First Design Patterns, O¡¯Reilly
Links:
? Apex Design Patterns, Salesforce https://developer.salesforce.com/page/Apex_Design_Patterns
? Force.com Apex Code Developer's Guide https://developer.salesforce.com/docs/atlas.en-
us.apexcode.meta/apexcode/