2

I am trying to embed a custom VF page into my Accounts layout. I believe my error is in the standardController. I assumed it should be SObject but it did not work and now I am not 100% sure what it should be. I have tried a number of variations with no luck. Is the standardController where I am going wrong? Any advice to point me in the right direction would be greatly appreciated!

I am getting error

Unknown constructor 'noteandtask_controller.noteandtask_controller(ApexPages.StandardController controller)'

VF Code:

    <apex:page standardController="Account" extensions="noteandtask_controller">
        <apex:pageBlock>
        <apex:pageBlockTable value="{!tasksAndNotes}" var="record">
        .....
    </apex:page>

APEX Code:

public class noteandtask_controller {
public List<SObject> tasksAndNotes {get; private set;}
public List<SObject> t {get;set;}
public List<SObject> n {get;set;}

public noteandtask_controller(){
    tasksAndNotes = new List<SObject>();
    t = [Select CreatedById, Subject, Description, CreatedDate From Task];
    n = [Select CreatedById, Title, Body,CreatedDate From Note];
    tasksAndNotes.addAll(t);
    tasksAndNotes.addAll(n);

    System.debug('the  t list is: ' + t);
    System.debug('the  n list is: ' + n);
    System.debug('the tasksAndNotes list is: ' + tasksAndNotes);
    }
}
3

If you are extending a standard controller then the extension controller class requires a standardcontroller as a constructor parameter

So your constructor will look like below

public noteandtask_controller(ApexPages.StandardController stdController){
  tasksAndNotes = new List<SObject>();
  t = [Select CreatedById, Subject, Description, CreatedDate From Task];
  n = [Select CreatedById, Title, Body,CreatedDate From Note];
  tasksAndNotes.addAll(t);
  tasksAndNotes.addAll(n);

   System.debug('the  t list is: ' + t);
   System.debug('the  n list is: ' + n);
   System.debug('the tasksAndNotes list is: ' + tasksAndNotes);
  }
}
  • Thank you, I tried that earlier and for some reason my developer console is lagging. I had to save it and close out of the console 3 times before the changes took. Frustrating. But thank you for confirming that this is what needed to happen! – Olivia Jul 15 '16 at 14:57
2

Change your constructor of your extension class into:

public noteandtask_controller(ApexPages.StandardController stdController){
//...

And your issue will be gone. For a standardcontroller extension class, the constructor needs to take standardController as the parameter

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.