1

I am getting this error when I am running my visualforce page

Below is my apex extension class: public with sharing class ExtensionAccount {

    public ExtensionAccount(ApexPages.StandardController controller) {

    }
    private final Account acct;  

    // The constructor passes in the standard controller defined
    // in the markup below
    public ExtensionAccount(ApexPages.StandardSetController controller) {
        this.acct = (Account)controller.getRecord(); 
    }    

    public ApexPages.StandardSetController TaskRecords {
        get {
            if(TaskRecords == null) {
                TaskRecords = new ApexPages.StandardSetController(
                    Database.getQueryLocator([SELECT AccountId FROM Task Where WhatId IN 
                        (Select id From Opportunity Where AccountId = :acct.Id)]));
            }
            return TaskRecords ;
        }
        private set;
    }
    public List<Task> getTaskList() {
         return (List<Task>) TaskRecords.getRecords();
    }  
}

Visualforce page

<apex:page standardController="Account" extensions="ExtensionAccount" sidebar="false"> 
<apex:pageBlock title="Opportunity"> 
<apex:pageBlockSection > 
<apex:dataList value="{!TaskList}" var="task" type="1"> {!task.accountid} </apex:dataList> 
</apex:pageBlockSection> 
</apex:pageBlock> 
</apex:form> 
</apex:page>
  • 1
    code looks good to me. Are you passing Account Id in url ? – Ratan Paul Feb 13 '16 at 10:20
  • Account should be initialized in constructor. And from where are you getting acct.Id? – Ysr Shk Feb 13 '16 at 10:21
  • <apex:page standardController="Account" extensions="ExtensionAccount" sidebar="false"> <apex:pageBlock title="Opportunity"> <apex:pageBlockSection > <apex:dataList value="{!TaskList}" var="task" type="1"> {!task.accountid} </apex:dataList> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page> – Rachit Joshi Feb 13 '16 at 10:23
  • this is my visualforce page – Rachit Joshi Feb 13 '16 at 10:24
  • 1
    @RachitJoshi You need to pass account Id in url – Ratan Paul Feb 13 '16 at 10:25
0

Since you are using single account id then add this.acct = (Account)controller.getRecord(); in your StandardController

public ExtensionAccount(ApexPages.StandardController controller) {
       this.acct = (Account)controller.getRecord(); //Add this line
    }
    private final Account acct;  

    // The constructor passes in the standard controller defined
    // in the markup below
    public ExtensionAccount(ApexPages.StandardSetController controller) {
        this.acct = (Account)controller.getRecord(); 
    }    

Edit

 public ExtensionAccount(ApexPages.StandardController controller) {
      this.acct = (Account)controller.getRecord();
    }
    private final Account acct;  

    // The constructor passes in the standard controller defined
    // in the markup below
    public ExtensionAccount(ApexPages.StandardSetController controller) {
        this.acct = (Account)controller.getRecord(); 
    }    


    public List<Task> getTaskList() {
         return [SELECT AccountId FROM Task Where WhatId IN (Select id From Opportunity Where AccountId = :acct.Id)];
    }  
}
  • The error is gone. – Rachit Joshi Feb 13 '16 at 10:47
  • Visualforce Error Help for this Page List controllers are not supported for Task – Rachit Joshi Feb 13 '16 at 10:48
  • now i am geting this error – Rachit Joshi Feb 13 '16 at 10:48
  • Error: Compile Error: Method does not exist or incorrect signature: Database.Query(List<Task>) at line 16 column 17 – Rachit Joshi Feb 13 '16 at 11:01
  • 1
    Thanks. I was just trying to compare my class with the one you create – Rachit Joshi Feb 13 '16 at 12:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.