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
Bill BlockBill Block 

VF Page not querying current record results anymore?

Hi all, i'm still learning some ins and outs of VF/Apex and ran into a rather weird problem i'm hoping someone could help me figure out. This might be more of an apex question.

I'm working on a set of VF pages that displays all related task/event information within a table. Right now i'm just working on a VF page for the Opportunity. 

I was able to successfully get this information queried onto the table/VF page with it only showing only the current records related tasks/events... (and not other records) but then I went to clone the VF page I had created and suddenly the VF page stopped showing queried results for the Opportunity record I had clicked on.

The only way I've been able to get this information to re-populate on the table was to go into the class extension I wrote and remove the WHERE clause (where it's supposed to be pulling the recordID of the opportunity)... however this isn't ideal because it then causes the VF page to display every task/event instead of those pertaining to just the Opportunity record I have selected. 

I definitely think it's got something to do with the way i'm trying to query the record ID but i'm not 100% sure because it seemed like it was working just fine up until I tried cloning the VF page.

Here's the VF Page:
 
<apex:page standardController="Opportunity" lightningStylesheets="true" extensions="CombinedActivitiesSortingExtension">
<apex:form >
<apex:pageBlock title="Task History">
<apex:pageBlockTable value="{!taskinfo}" var="task">
<apex:column value="{!task.activitydate}"/>
<apex:column value="{!task.subject}"/>
<apex:column value="{!task.description}"/>
<apex:column value="{!task.status}"/>
</apex:pageBlockTable>
</apex:pageBlock>
<apex:pageBlock title="Event History">
<apex:pageblockTable value="{!eventinfo}" var="event">
<apex:column value="{!event.activitydate}"/>
<apex:column value="{!event.subject}"/>
<apex:column value="{!event.description}"/>
</apex:pageblockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

And heres the extension I wrote 
 
public with sharing class CombinedActivitiesSortingExtension {
    
    Id oppID;
    private final ID taskid;
    Public List<Task> taskinfo {get;set;}
    Public List<Event> eventinfo {get;set;}
    
    
    
    Public CombinedActivitiesSortingExtension(ApexPages.StandardController stdController) {
        
        oppID = stdController.getId();
        taskid = stdController.getId();
        
        
        taskinfo =   [SELECT ActivityDate, Subject, Description, Status
                      FROM Task
                      WHERE Id= :oppID
                      ORDER BY ActivityDate desc];
        
        eventinfo = [SELECT ActivityDate, Subject, Description
                     FROM Event
                     WHERE Id= :oppID
                     ORDER BY ActivityDate desc];
                     
                       
                     
      
            
   
    }


}

Any help would be super appreciated.
Thank you!







 
Best Answer chosen by Bill Block
David Zhu 🔥David Zhu 🔥
You may need to modify the class.
Public CombinedActivitiesSortingExtension(ApexPages.StandardController stdController) {
        oppID = stdController.getId();
              
        taskinfo =   [SELECT ActivityDate, Subject, Description, Status
                      FROM Task
                      WHERE WhatId= :oppID
                      ORDER BY ActivityDate desc];
        
        eventinfo = [SELECT ActivityDate, Subject, Description
                     FROM Event
                     WHERE WhatId= :oppID
                     ORDER BY ActivityDate desc];
   
    }

 

All Answers

David Zhu 🔥David Zhu 🔥
You may need to modify the class.
Public CombinedActivitiesSortingExtension(ApexPages.StandardController stdController) {
        oppID = stdController.getId();
              
        taskinfo =   [SELECT ActivityDate, Subject, Description, Status
                      FROM Task
                      WHERE WhatId= :oppID
                      ORDER BY ActivityDate desc];
        
        eventinfo = [SELECT ActivityDate, Subject, Description
                     FROM Event
                     WHERE WhatId= :oppID
                     ORDER BY ActivityDate desc];
   
    }

 
This was selected as the best answer
Bill BlockBill Block
Thanks David, that did the trick!