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>
6
  • 1
    code looks good to me. Are you passing Account Id in url ? Commented Feb 13, 2016 at 10:20
  • Account should be initialized in constructor. And from where are you getting acct.Id? Commented Feb 13, 2016 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> Commented Feb 13, 2016 at 10:23
  • this is my visualforce page Commented Feb 13, 2016 at 10:24
  • 1
    @RachitJoshi You need to pass account Id in url Commented Feb 13, 2016 at 10:25

1 Answer 1

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)];
    }  
}
12
  • The error is gone. Commented Feb 13, 2016 at 10:47
  • Visualforce Error Help for this Page List controllers are not supported for Task Commented Feb 13, 2016 at 10:48
  • now i am geting this error Commented Feb 13, 2016 at 10:48
  • Error: Compile Error: Method does not exist or incorrect signature: Database.Query(List<Task>) at line 16 column 17 Commented Feb 13, 2016 at 11:01
  • 1
    Thanks. I was just trying to compare my class with the one you create Commented Feb 13, 2016 at 12:28

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.