2

My goal is to create a btn on a task related list that launches a visualforce page and does a redirect. I tried using a StandardSetController, but Error: List controllers are not supported for Task . I turned to a custom controller, but I'm not able to get it to work. Below is some code that compiles, but the VF page does not show up as a viable selection in the drop down.

Can you tell me what's going on, and why it doesn't show in the drop down?

<apex:page controller="TaskController" >

</apex:page>

.

public with sharing class TaskController{

String retURL;
Task theTask;
String who_Id;
String what_Id;

public ApexPages.StandardSetController setcon {get; set;}

public TaskController(){
   theTask = new Task();
}

}

2 Answers 2

3

http://login.salesforce.com/help/doc/en/defining_custom_links_fields.htm

  • Visualforce pages used as custom links on the home page cannot specify a controller.
  • Visualforce pages used as custom buttons or links on detail pages must specify a standard controller of the same object.
  • Visualforce pages used as custom list buttons must use a standard list controller of the same object.

So you ideally should add <apex:page standardController="Task" recordSetVar="tasks" extensions="TaskController">. EDIT: We can't use StandardSetControllers with Tasks or Activities.

Another way would be to just cheat: set Content Source to URL (or Javascript if you need something complex that can't be achieved with merge fields) and specify the /apex/MyPage in the Content of the button. It's less ideal as it's not a real reference ("Where is this used", check performed before you delete a page etc) but well...

enter image description here

And the result (after adding to page layout of course):

enter image description here

You could pass any arguments you need. Maybe even check out the HTTP Referer header in ApexPages.currentPage().getHeaders() to check from which record's page was the button clicked if you can't pass Ids (but don't count on it's presence as it's the user's browser that might decide not to send it).

Just remember that if you plan to insert the Task & direct to edit page i'll fail as constructors, getters & setters cannot have side effects (such as DML). You'd need page action for that.

3
  • My friend, there's an important caveat... "Error: List controllers are not supported for Task " Commented Jun 3, 2013 at 21:15
  • Oh, bummer. And looks like same with Activity (salesforce.com/us/developer/docs/pages/Content/…). Then I guess either the "cheat" or maybe you could pull off the trick with standardController="sObject" ;)
    – eyescream
    Commented Jun 3, 2013 at 21:18
  • can you take a look at the code I posted? any ideas? Commented Jun 3, 2013 at 21:39
4

If the only reason you need the StandardSetController is to so you can use the resulting visualforce page as the target for the button you can work around this pretty easily. You just need to pass in any parameters to the url for your apex page in the custom button and manually grab them when the controller is loaded. For example, if the button was on the task related list for an account you could pass in the account id.

Visualforce Page

<apex:page controller="MyNewTaskController">

Custom Button

  • Type: Task List Button
  • Source: URL
  • URL: /apex/MyApexPage?whatId={!Account.Id}

Controller

public class MyNewTaskController {

  public Task task { get; set; }

  public MyNewTaskController() {
    task = new Task(whatId = ApexPages.currentPage().getParameters().get('whatId');
  }
}

Of course if you need the StandardSetController for pagination you're SOL. You'll need to roll your own pagination.

1
  • Thanks Ralph, your help with eyescreams helped with the issue. Commented Jun 5, 2013 at 18:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .