function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MycodexMycodex 

Create custom related list of Activities

Hi all, I'm trying to make a PDF version of a custom detail page. I was looking to add the related list of Open Activities and Activity History. I can't seem to figure out the SQL statement to combine the Task and Event objects together so they show as Activities.

Any help would be useful.

Code:
public List<Event> getEvents() { 
        return [SELECT id, whatID, subject, startdatetime, whoID, accountID
           FROM Event
           WHERE whatID = :ApexPages.currentPage().getParameters().get('id')
           ORDER BY startdatetime DESC];
    }

 

Sam.arjSam.arj
Use a standard detail component to show the details of your object and then render the page as PDF:

Code:
<apex:Page standardController="Contact" renderAs="PDF">
  <apex:detail relatedList="true" relatedListHover="fasle"></apex:detail>
</apex:Page>

relatedListHover is set to off because you want to your page to be print friendly.

MycodexMycodex
Hi Sam,

This is for a custom object I call a Trip Report. Could I still use a standardcontroller to make this happen? Here is the current controller and visualforce page I use:

Code:
public class TripReportController {

    /* Constructor of the class where we default the above property values */
    public TripReportController() {
        }

    public Trip_Report__c getTripReport() { 
        return [SELECT id, name, ownerID, createdbyID, lastmodifiedbyID, start_date__c, end_date__c, city__c
                FROM trip_report__c 
                WHERE id = :ApexPages.currentPage().getParameters().get('id')]; 
    }
    
    public List<Opportunity> getOpportunities() { 
        return [SELECT id, trip_report__c, name, accountID, type, business_unit__c, stagename, amount, closeDate
           FROM Opportunity
           WHERE trip_report__c = :ApexPages.currentPage().getParameters().get('id') 
           ORDER BY closeDate DESC ];
    }
    
    public List<Event> getEvents() { 
        return [SELECT id, whatID, subject, startdatetime, whoID, 
            accountID, purpose__c, payoff__c, general_notes__c, 
            other_XL_attendees__c, Other_Client_Attendees__c
           FROM Event
           WHERE whatID = :ApexPages.currentPage().getParameters().get('id')
           ORDER BY startdatetime DESC];
    }
}

 
Code:
<apex:page Controller="TripReportController" tabStyle="Trip_Report__c" sidebar="false" showheader="false" >
<apex:sectionHeader title="Trip Report" subtitle="{!TripReport.name}"/>
<apex:pageBlock title="Trip Report Details" >
    <apex:pageBlockSection columns="2">
        <apex:outputfield value="{!TripReport.name}"/>
        <apex:outputfield value="{!TripReport.ownerID}"/>
        <apex:outputfield value="{!TripReport.Start_Date__c}"/>
        <apex:outputfield value="{!TripReport.End_Date__c}"/>
        <apex:outputfield value="{!TripReport.City__c}"/>
        <apex:outputlabel value=""/>
        <apex:outputfield value="{!TripReport.createdbyID}"/>
        <apex:outputfield value="{!TripReport.lastmodifiedbyID}"/>
    </apex:pageBlockSection>
</apex:PageBlock>
<apex:PageBlock title="Opportunities" rendered="{!NOT(ISNULL(opportunities))}">
    <apex:pageBlockTable value="{!opportunities}" var="opportunity" >
        <apex:column value="{!opportunity.name}"/>
        <apex:column value="{!opportunity.accountID}"/>
        <apex:column value="{!opportunity.Business_Unit__c}"/>
        <apex:column value="{!opportunity.type}"/>
        <apex:column value="{!opportunity.stagename}"/>
        <apex:column value="{!opportunity.amount}"/>
        <apex:column value="{!opportunity.closeDate}"/>
    </apex:PageBlockTable>
</apex:pageBlock>
<apex:PageBlock title="Activities">
    <apex:pageBlockTable value="{!events}" var="event" >
        <apex:column value="{!event.subject}"/>
        <apex:column value="{!event.startdatetime}"/>
        <apex:column value="{!event.whoID}"/>
        <apex:column value="{!event.accountID}"/>
        <apex:column value="{!event.Purpose__c}"/>
        <apex:column value="{!event.Payoff__c}"/>
        <apex:column value="{!event.General_Notes__c}"/>
        <apex:column value="{!event.Other_XL_Attendees__c}"/>
        <apex:column value="{!event.Other_Client_Attendees__c}"/>
    </apex:PageBlockTable>
</apex:pageBlock>
</apex:page>