• Michael Snow 5
  • NEWBIE
  • 10 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 5
    Replies
Hi There,

So I am attempting to create a VF page that brings in all Activities onto an Opportunity from the Opportunities Primary Contact that is identified on the Opportunity. I attempted to create a custom controller class to complete this but then learned that you have to use the standard controller i norder to be able to embed the VF section onto SFDC. 

Also unfortunately now you can no longer switch the Controller from a standard controller to a custom controller anymore :( 

Any ideas on how to work around this? I shared the VF page and custom controller below

VF Page:
<apex:page controller="related_activities_from_contacts">
    <apex:form >
        <apex:pageBlock title="Activites with Contacts" id="activites_list">
            <!-- Events List -->
            <apex:pageBlockTable value="{! events }" var="evt">
                <apex:column value="{! evt.ActivityDate }"/>
                <apex:column value="{! evt.ActivityType }"/>
                <apex:column value="{! evt.Description }"/>
                <apex:column value="{! evt.OwnerId }"/>
                <apex:column value="{! evt.PrimaryWhoId }"/>
                <apex:column value="{! evt.Subject }"/>
                <apex:column value="{! evt.WhoId }"/>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Custom Controller:
public class related_activities_from_contacts {
    // This would be the Id of the Opportunity
    Id OppID = (Id) ApexPages.currentPage().getParameters().get('id');
    // Select only one of those contacts for use in the Contact ID Below
    OpportunityContactRole[] contactRoleArray =
        [select ContactID
         from OpportunityContactRole 
         where OpportunityId =: OppID AND isPrimary = TRUE];
    
    // Id ContactID = contactRoleArray[0];
    public List<ActivityHistory> getEvents() {
        List<ActivityHistory> results = Database.query(
            'SELECT ActivityDate, ActivityType, Description, OwnerId, PrimaryWhoId, Subject, WhoId' +
            'FROM ActivityHistory ' +
            'Where WhoId =' + contactRoleArray[0]
        );
        return results;
    }  
}