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
Rakesh K 60Rakesh K 60 

Unknown error in my VF page and there is no Error Statement

Hi,

I'm trying to create a VF page that will listdown all the Tasks related to current Account and here is my VF code.
 
<apex:page standardController="Account" extensions="MyCustomController"  >
    <apex:form >
        <apex:pageBlock id="pb">
            <apex:pageBlockTable value="{!TaskList}" var="d">
                <apex:column headerValue="Subject">   
                    <apex:outputField value="{!d.Subject}">  
                    </apex:outputField> </apex:column>
            </apex:pageBlockTable>
        </apex:pageblock>
    </apex:form>
</apex:page>

And my Controller is as below.
 
public class MyCustomController {
    Public List<SObject> TaskList{get;set;}
    String currentRecordId ; 
    public MyCustomController(ApexPages.StandardController controller) {
        TaskList= new List<SObject>();
        currentRecordId  = ApexPages.CurrentPage().getparameters().get('id');
        System.debug(currentRecordId);
        List<Contact> cts = [Select Id, Name from Contact where AccountId=:currentRecordId];
        List<sObject> events = new List<sObject>();
        for(Contact c: cts){
            List<Task> tskL = [Select Id, Subject from Task where whoId=:c.Id order by ActivityDate desc];
            for(Task t: tskl){
                events.add(t); 
            }
            
            List<Event> evtL = [Select Id, Subject from Event where whoId=:c.Id order by ActivityDate desc];
            for(Event e: evtL){
                events.add(e); 
            }
        }
        
        TaskList = events;
        System.debug(TaskList);
    }
    
}

When I run this, I get the error as below.

User-added imageCan someone please let me know where I went wrong?
And I apologise if there are is any silly mistake. I'm new to VF, U started my journey with Lightning.

Thanks
David Zhu 🔥David Zhu 🔥
With standard controller extension, you may need to change line 06.

currentRecordId = (Account)controller.getRecord().id;

with ApexPages.CurrentPage().getparameters().get('id');
it tries to get value from parameter id in the url, like 
https://xxxxx.salesforce.com?id=001xxxxxxxxxxxxxxxx
 
Maharajan CMaharajan C
HI Rakesh,

The problem is in below line:

<apex:outputField value="{!d.Subject}">   --> wrong one
<apex:outputField value="{!d['Subject']}">     --> Correct Way:

While iterating the Sobject you have use the fields expressions as value="{!d['Subject']}"  . Don't use the normal way of data binding it will not work.

Update VF Page:
 
<apex:page standardController="Account" extensions="MyCustomController">
    <apex:form >
        <apex:pageBlock id="pb">
            <apex:pageBlockTable value="{!TaskList}" var="d">
                <apex:column headerValue="Subject">   
                    <apex:outputField value="{!d['Subject']}">  
                    </apex:outputField> 
                </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Thanks,
Maharajan.C