SlideShare a Scribd company logo
Custom Event Handling with
Visualforce
Opportunity Contact Roles
Ritesh Aswaney, Technical Solution Architect, salesforce.com
@techtrekker
Safe harbor
Safe harbor statement under the Private Securities Litigation Reform Act of 1995:
This presentation may contain forward-looking statements that involve risks, uncertainties, and assumptions. If any such uncertainties
materialize or if any of the assumptions proves incorrect, the results of salesforce.com, inc. could differ materially from the results
expressed or implied by the forward-looking statements we make. All statements other than statements of historical fact could be
deemed forward-looking, including any projections of product or service availability, subscriber growth, earnings, revenues, or other
financial items and any statements regarding strategies or plans of management for future operations, statements of belief, any
statements concerning new, planned, or upgraded services or technology developments and customer contracts or use of our services.
The risks and uncertainties referred to above include – but are not limited to – risks associated with developing and delivering new
functionality for our service, new products and services, our new business model, our past operating losses, possible fluctuations in our
operating results and rate of growth, interruptions or delays in our Web hosting, breach of our security measures, the outcome of any
litigation, risks associated with completed and any possible mergers and acquisitions, the immature market in which we operate, our
relatively limited operating history, our ability to expand, retain, and motivate our employees and manage our growth, new releases of our
service and successful customer deployment, our limited history reselling non-salesforce.com products, and utilization and selling to
larger enterprise customers. Further information on potential factors that could affect the financial results of salesforce.com, inc. is
included in our annual report on Form 10-K for the most recent fiscal year and in our quarterly report on Form 10-Q for the most recent
fiscal quarter. These documents and others containing important disclosures are available on the SEC Filings section of the Investor
Information section of our Web site.
Any unreleased services or features referenced in this or other presentations, press releases or public statements are not currently
available and may not be delivered on time or at all. Customers who purchase our services should make the purchase decisions
based upon features that are currently available. Salesforce.com, inc. assumes no obligation and does not intend to update these
forward-looking statements.
Ritesh Aswaney
Technical Solution Architect
@techtrekker
About : me
Technical Solution Architect
§  Salesforce Services
•  Based in London
•  Certified Advanced Developer
•  On the Road to CTA
§  Experience
•  10 years of Enterprise Software
•  4 years of working on the Force.com Platform
•  StackExchange junkie
Second among equals
Object Types
§  ‘First Class’ Objects
•  Triggers, Workflow
•  Custom Fields
§  Non ‘First Class’ Objects
•  No Triggers or Workflow
•  ‘Junction’ Objects
•  No Custom Fields
Business Need
Junction Objects model real world business relationships, hotbed
of custom business logic
§  Opportunity / Account Contact Role
•  Sales Team need to know if Business Decision Maker Changes
•  Downstream Systems notified of changes in OCR
§  Account Team
•  Custom Business Logic when people are added to Account Teams
Solution Option 1: Custom Junction Object
§  Lose OOTB functionality such as sharing with teams
§  Triggers, Workflow can be created
§  Custom Fields can be added
§  Overhead of keeping (Custom & Standard Object) records in sync
Solution Option 2: Custom Visualforce Section
§  Retain OOTB functionality
§  ‘Touch’ Parent Object and update custom field
§  Multiplex Triggers, Wokflows to cater for Junction Objects
§  Integration Hooks to trigger Outbound Messages to External Systems
Meet the Paramters
§  saveURL
•  Redirect to this URL when a user hits Save
§  retURL
•  Redirect to this URL when a user hits Cancel
§  https://cs1.salesforce.com/02Z/e?retURL=
%2FRECORD_ID&saveURL=/apex/VF_PAGE_NAME
Solution Design : How does it flow
Demo
Solution Elements : URL Decoration
$j( 'input[type="button"]', this ).each(function()
$j( this ).attr('onclick', "window.parent.location=" + onclicklink +
"&saveURL=/apex/SavePage?actionURI={!objId}_" + rlName + "';");!
});!
!
$j( 'a.actionLink', this ).each(function() {!
onClickUrl += '&saveURL=/apex/SavePage?actionURI={!objId}_'+ rlName;!
$j( this ).attr('onclick', "window.parent.location='" + onClickUrl +
"'" ); });!
!
Solution Elements : Save Handler
String[] tokens = actionURI.split('_');!
Id entityId = tokens[0];!
String relatedList = tokens[1];!
!
if(entityId.getSObjectType() == Opportunity.sObjectType){!
! !if(relatedList == 'Contact Roles')!
handleOpportunityContactRole(entityId); //callback!
else if(relatedList == 'Opportunity Team')!
handleOpportunityTeam(entityId); //callback!
!
}!
Solution Element: Visualforce Event Handler Page
§  Invoking Apex Code (Controller) on Page Load
§  Use action attribute
<apex:page action="{!handleOnLoad}"
controller="SavePageCon”>
Solution Elements : Dynamic Visualforce Controller
if(objId.getSObjectType() == Opportunity.sObjectType)!
!Schema.DescribeSObjectResult R =!
!Opportunity.SObjectType.getDescribe();!
!
List<Schema.ChildRelationship> C = R.getChildRelationships(); !
List<String> relations = new List<String>();!
! ! for (Schema.ChildRelationship cr: C) {//only some relationships!
! ! !if ( (cr.getRelationshipName().contains('Role’) ) !
relations.add(relName);!
! ! }!
Solution Elements : Dynamic Visualforce Controller
public Component.Apex.OutputPanel getOpportunityRelatedLists() {!
!Component.Apex.OutputPanel dynOutPanel= new
!Component.Apex.OutputPanel();!
for(String rel: relations) {!
Component.Apex.RelatedList dynRelList = new
! ! ! !Component.Apex.RelatedList();!
dynRelList.list = rel;!
dynOutPanel.childComponents.add(dynRelList);!
}!
return dynOutPanel; !
!}!
Solution Element: Dynamic Visualforce Page
§  Visualforce Markup generated dynamically in the Controller
§  Dynamic generation of custom related lists based on the relationship
<apex:dynamicComponent componentValue="{!
OpportunityRelatedLists}"/>!
!
!
Ritesh Aswaney
Technical Solution Architect,
@techtrekker
Visualforce Hack for Junction Objects

More Related Content

PPT
Building Visualforce Custom Events Handlers
PDF
The Visual Delta Force: Dynamic Visualforce Components
PDF
Making Your Apex and Visualforce Reusable
PDF
Developing Interactive Tables and Charts in Visualforce
PDF
Live coding with LWC
PPT
The Salesforce Einstein Product Team: Ask Us Anything!
PPTX
Build Better Communities with Lightning
PPTX
Webinar: Build Apps Customers Love as a Salesforce Developer
Building Visualforce Custom Events Handlers
The Visual Delta Force: Dynamic Visualforce Components
Making Your Apex and Visualforce Reusable
Developing Interactive Tables and Charts in Visualforce
Live coding with LWC
The Salesforce Einstein Product Team: Ask Us Anything!
Build Better Communities with Lightning
Webinar: Build Apps Customers Love as a Salesforce Developer

What's hot (20)

PPTX
Build custom user interfaces for your Salesforce data with the UI API
PDF
Building Complex Traversing & Branching Apps Using Visual Workflows and Apex
PDF
Lightning Connect Custom Adapters: Connecting Anything with Salesforce
PDF
Einstein Analytics for Developers
PDF
Javascript Security and Lightning Locker Service
PPTX
Build Smarter Apps with Einstein Platform Services
PDF
Build Smarter Apps with Einstein Object Detection
PDF
#DF17Recap series: Integrate apps easier with the Salesforce platform
PPTX
#Df17 Recap Series Build Apps Faster with the Salesforce Platform
PPTX
Lightning Updates: Summer, Winter & Beyond
PPTX
CodeLive: Build Lightning Web Components faster with Local Development
PDF
Lightning customization with lightning app builder
PPTX
Lightning Developer Experience, Eclipse IDE Evolved
PPTX
SalesforceDX Demo by Manish
PPTX
Embed Customer Support into your Apps with Snap-ins
PPTX
Build and Package Lightning Components for Lightning Exchange
PDF
Easy No-Code Integrations with External Services and Visual Flow
PPTX
Custom Metadata Data Types
PPTX
Quit Jesting and Test your Lightning Web Components, Phillipe Ozil
PDF
A Developer's Guide to Visual Workflow
Build custom user interfaces for your Salesforce data with the UI API
Building Complex Traversing & Branching Apps Using Visual Workflows and Apex
Lightning Connect Custom Adapters: Connecting Anything with Salesforce
Einstein Analytics for Developers
Javascript Security and Lightning Locker Service
Build Smarter Apps with Einstein Platform Services
Build Smarter Apps with Einstein Object Detection
#DF17Recap series: Integrate apps easier with the Salesforce platform
#Df17 Recap Series Build Apps Faster with the Salesforce Platform
Lightning Updates: Summer, Winter & Beyond
CodeLive: Build Lightning Web Components faster with Local Development
Lightning customization with lightning app builder
Lightning Developer Experience, Eclipse IDE Evolved
SalesforceDX Demo by Manish
Embed Customer Support into your Apps with Snap-ins
Build and Package Lightning Components for Lightning Exchange
Easy No-Code Integrations with External Services and Visual Flow
Custom Metadata Data Types
Quit Jesting and Test your Lightning Web Components, Phillipe Ozil
A Developer's Guide to Visual Workflow

Similar to Visualforce Hack for Junction Objects (20)

PPTX
Using Salesforce1 to Manage Your Salesforce Org
PPTX
Webinar using salesforce1 to manage your salesforce org final
PPT
Salesforce1 Platform for programmers
PDF
Unlock SAP - Release the potential of your existing backend systems with Sale...
PPT
Aan004 Wilson 091807
PDF
Salesforce Spring'15 release overview
PDF
Just-In-Time Sharing Using Apex
PPTX
[MBF2] Plate-forme Salesforce par Peter Chittum
PDF
Coding for Declarative Customizations: How We Do It in Salesforce.com IT
PPTX
Force.com Friday: Intro to Visualforce (May 8, 2015)
PDF
New from Salesforce Labs
PDF
Making External Web Pages Interact With Visualforce
PPTX
Salesforce Campus Tour - Declarative
PPTX
Solving Complex Data Load Challenges
PPTX
Javascript and Remote Objects on Force.com Winter 15
PPTX
Salesforce Campus Tour - Developer Advanced
PPTX
Salesforce Campus Tour - Developer Intro
PDF
Summer '18 Developer Highlights
PDF
Introduction to Force.com
PDF
Publish Your First App on the AppExchange
Using Salesforce1 to Manage Your Salesforce Org
Webinar using salesforce1 to manage your salesforce org final
Salesforce1 Platform for programmers
Unlock SAP - Release the potential of your existing backend systems with Sale...
Aan004 Wilson 091807
Salesforce Spring'15 release overview
Just-In-Time Sharing Using Apex
[MBF2] Plate-forme Salesforce par Peter Chittum
Coding for Declarative Customizations: How We Do It in Salesforce.com IT
Force.com Friday: Intro to Visualforce (May 8, 2015)
New from Salesforce Labs
Making External Web Pages Interact With Visualforce
Salesforce Campus Tour - Declarative
Solving Complex Data Load Challenges
Javascript and Remote Objects on Force.com Winter 15
Salesforce Campus Tour - Developer Advanced
Salesforce Campus Tour - Developer Intro
Summer '18 Developer Highlights
Introduction to Force.com
Publish Your First App on the AppExchange

Recently uploaded (20)

PDF
Encapsulation theory and applications.pdf
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Empathic Computing: Creating Shared Understanding
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Approach and Philosophy of On baking technology
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPT
Teaching material agriculture food technology
PPTX
Machine Learning_overview_presentation.pptx
PDF
Getting Started with Data Integration: FME Form 101
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
Encapsulation theory and applications.pdf
Accuracy of neural networks in brain wave diagnosis of schizophrenia
Per capita expenditure prediction using model stacking based on satellite ima...
Unlocking AI with Model Context Protocol (MCP)
Empathic Computing: Creating Shared Understanding
Dropbox Q2 2025 Financial Results & Investor Presentation
20250228 LYD VKU AI Blended-Learning.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Approach and Philosophy of On baking technology
MIND Revenue Release Quarter 2 2025 Press Release
Digital-Transformation-Roadmap-for-Companies.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
Teaching material agriculture food technology
Machine Learning_overview_presentation.pptx
Getting Started with Data Integration: FME Form 101
Group 1 Presentation -Planning and Decision Making .pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?

Visualforce Hack for Junction Objects

  • 1. Custom Event Handling with Visualforce Opportunity Contact Roles Ritesh Aswaney, Technical Solution Architect, salesforce.com @techtrekker
  • 2. Safe harbor Safe harbor statement under the Private Securities Litigation Reform Act of 1995: This presentation may contain forward-looking statements that involve risks, uncertainties, and assumptions. If any such uncertainties materialize or if any of the assumptions proves incorrect, the results of salesforce.com, inc. could differ materially from the results expressed or implied by the forward-looking statements we make. All statements other than statements of historical fact could be deemed forward-looking, including any projections of product or service availability, subscriber growth, earnings, revenues, or other financial items and any statements regarding strategies or plans of management for future operations, statements of belief, any statements concerning new, planned, or upgraded services or technology developments and customer contracts or use of our services. The risks and uncertainties referred to above include – but are not limited to – risks associated with developing and delivering new functionality for our service, new products and services, our new business model, our past operating losses, possible fluctuations in our operating results and rate of growth, interruptions or delays in our Web hosting, breach of our security measures, the outcome of any litigation, risks associated with completed and any possible mergers and acquisitions, the immature market in which we operate, our relatively limited operating history, our ability to expand, retain, and motivate our employees and manage our growth, new releases of our service and successful customer deployment, our limited history reselling non-salesforce.com products, and utilization and selling to larger enterprise customers. Further information on potential factors that could affect the financial results of salesforce.com, inc. is included in our annual report on Form 10-K for the most recent fiscal year and in our quarterly report on Form 10-Q for the most recent fiscal quarter. These documents and others containing important disclosures are available on the SEC Filings section of the Investor Information section of our Web site. Any unreleased services or features referenced in this or other presentations, press releases or public statements are not currently available and may not be delivered on time or at all. Customers who purchase our services should make the purchase decisions based upon features that are currently available. Salesforce.com, inc. assumes no obligation and does not intend to update these forward-looking statements.
  • 3. Ritesh Aswaney Technical Solution Architect @techtrekker
  • 4. About : me Technical Solution Architect §  Salesforce Services •  Based in London •  Certified Advanced Developer •  On the Road to CTA §  Experience •  10 years of Enterprise Software •  4 years of working on the Force.com Platform •  StackExchange junkie
  • 5. Second among equals Object Types §  ‘First Class’ Objects •  Triggers, Workflow •  Custom Fields §  Non ‘First Class’ Objects •  No Triggers or Workflow •  ‘Junction’ Objects •  No Custom Fields
  • 6. Business Need Junction Objects model real world business relationships, hotbed of custom business logic §  Opportunity / Account Contact Role •  Sales Team need to know if Business Decision Maker Changes •  Downstream Systems notified of changes in OCR §  Account Team •  Custom Business Logic when people are added to Account Teams
  • 7. Solution Option 1: Custom Junction Object §  Lose OOTB functionality such as sharing with teams §  Triggers, Workflow can be created §  Custom Fields can be added §  Overhead of keeping (Custom & Standard Object) records in sync
  • 8. Solution Option 2: Custom Visualforce Section §  Retain OOTB functionality §  ‘Touch’ Parent Object and update custom field §  Multiplex Triggers, Wokflows to cater for Junction Objects §  Integration Hooks to trigger Outbound Messages to External Systems
  • 9. Meet the Paramters §  saveURL •  Redirect to this URL when a user hits Save §  retURL •  Redirect to this URL when a user hits Cancel §  https://cs1.salesforce.com/02Z/e?retURL= %2FRECORD_ID&saveURL=/apex/VF_PAGE_NAME
  • 10. Solution Design : How does it flow
  • 11. Demo
  • 12. Solution Elements : URL Decoration $j( 'input[type="button"]', this ).each(function() $j( this ).attr('onclick', "window.parent.location=" + onclicklink + "&saveURL=/apex/SavePage?actionURI={!objId}_" + rlName + "';");! });! ! $j( 'a.actionLink', this ).each(function() {! onClickUrl += '&saveURL=/apex/SavePage?actionURI={!objId}_'+ rlName;! $j( this ).attr('onclick', "window.parent.location='" + onClickUrl + "'" ); });! !
  • 13. Solution Elements : Save Handler String[] tokens = actionURI.split('_');! Id entityId = tokens[0];! String relatedList = tokens[1];! ! if(entityId.getSObjectType() == Opportunity.sObjectType){! ! !if(relatedList == 'Contact Roles')! handleOpportunityContactRole(entityId); //callback! else if(relatedList == 'Opportunity Team')! handleOpportunityTeam(entityId); //callback! ! }!
  • 14. Solution Element: Visualforce Event Handler Page §  Invoking Apex Code (Controller) on Page Load §  Use action attribute <apex:page action="{!handleOnLoad}" controller="SavePageCon”>
  • 15. Solution Elements : Dynamic Visualforce Controller if(objId.getSObjectType() == Opportunity.sObjectType)! !Schema.DescribeSObjectResult R =! !Opportunity.SObjectType.getDescribe();! ! List<Schema.ChildRelationship> C = R.getChildRelationships(); ! List<String> relations = new List<String>();! ! ! for (Schema.ChildRelationship cr: C) {//only some relationships! ! ! !if ( (cr.getRelationshipName().contains('Role’) ) ! relations.add(relName);! ! ! }!
  • 16. Solution Elements : Dynamic Visualforce Controller public Component.Apex.OutputPanel getOpportunityRelatedLists() {! !Component.Apex.OutputPanel dynOutPanel= new !Component.Apex.OutputPanel();! for(String rel: relations) {! Component.Apex.RelatedList dynRelList = new ! ! ! !Component.Apex.RelatedList();! dynRelList.list = rel;! dynOutPanel.childComponents.add(dynRelList);! }! return dynOutPanel; ! !}!
  • 17. Solution Element: Dynamic Visualforce Page §  Visualforce Markup generated dynamically in the Controller §  Dynamic generation of custom related lists based on the relationship <apex:dynamicComponent componentValue="{! OpportunityRelatedLists}"/>! ! !
  • 18. Ritesh Aswaney Technical Solution Architect, @techtrekker