Created
March 14, 2017 19:49
-
-
Save douglascayers/eee1d9c352a67cae4c8028ab32c6ff7c to your computer and use it in GitHub Desktop.
Example Visualforce page that shows Opportunities with or without Contact Roles.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public with sharing class SampleOpptyController { | |
public List<Opportunity> opportunities { get; set; } | |
public SampleOpptyController() { | |
this.opportunities = queryOpportunities(); | |
} | |
private List<Opportunity> queryOpportunities() { | |
return [ | |
SELECT | |
id, | |
name, | |
stageName, | |
closeDate, | |
( | |
SELECT | |
id, | |
contactId, | |
contact.firstName, | |
contact.lastName, | |
isPrimary, | |
role | |
FROM | |
OpportunityContactRoles | |
ORDER BY | |
isPrimary, | |
contact.name | |
) | |
FROM | |
Opportunity | |
ORDER BY | |
closeDate DESC | |
]; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<apex:page controller="SampleOpptyController"> | |
<apex:sectionHeader title="Opportunities with or without Contact Roles"/> | |
<apex:repeat var="oppty" value="{!opportunities}"> | |
<apex:pageBlock title="{!oppty.name}"> | |
<apex:pageBlockSection columns="2"> | |
<apex:outputField value="{!oppty.stageName}"/> | |
<apex:outputField value="{!oppty.closeDate}"/> | |
</apex:pageBlockSection> | |
<apex:pageBlockSection columns="1"> | |
<apex:repeat var="contactRole" value="{!oppty.opportunityContactRoles}"> | |
<apex:pageBlock title="{!contactRole.contact.firstName + ' ' + contactRole.contact.lastName}"> | |
<apex:pageBlockSection columns="2"> | |
<apex:outputField value="{!contactRole.isPrimary}"/> | |
<apex:outputField value="{!contactRole.role}"/> | |
</apex:pageBlockSection> | |
</apex:pageBlock> | |
</apex:repeat> | |
</apex:pageBlockSection> | |
</apex:pageBlock> | |
</apex:repeat> | |
</apex:page> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment