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
Mark SlavinMark Slavin 

Invoking a custom Task VF page via a List Button.

Hi,
I created a custom Task page based on a standart cotroller and would like to invoke it via a list button from contact's open activities. I'm not sure how to build a URL link which not only will invoke the page, but also pass a few arguments.
thanks
Scott HungScott Hung
Take a look at this post:  https://developer.salesforce.com/blogs/developer-relations/2009/05/calling-an-apex-class-directly-from-a-custom-button-or-link.html    Summary is to set the button's content source as URL and append the page URL along with your parameters. 
Mark SlavinMark Slavin
I've tried this approach, however it did not work for me, I was always getting errors.
Scott HungScott Hung
I finally got some time to play with this and found something that changed on the original link I posted.  The URL parameter should be "/apex/mypage" and not "/pages/mypage".  With the latter you'll get a "URL no longer exists" error.

To access URL parameters via VF reference the merge field "$CurrentPage.parameters.myparam".  
To access URL parameters via Apex class, create an extension and, in the constructor, set property = ApexPages.currentPage().getParameters().get('param2');

For example the URL field is: 
/apex/showAccount?myparam={!Account.Id}&param2={!Account.Name}

The VF page is:
<apex:page standardController="account" extensions="myAccountExtension">
  <apex:outputText value="VF parameter is {!$CurrentPage.Parameters.myparam}" />
  <br />
  <apex:outputText value="Apex class parameter is {!param}" />
</apex:page>

Apex class is:
public class myAccountExtension {
    Account acct;    
    string apexparam = 'Not me';

    public myAccountExtension(ApexPages.StandardController stdController) {
        this.acct = (Account)stdController.getRecord();
        apexparam = ApexPages.currentPage().getParameters().get('param2');
    }

    public string getparam() { return apexparam; }
}

Hope this helps!
Mark SlavinMark Slavin
Hi Scott, thanks for taking the time to respond to my question! Now, and this is my new struggle, what do I need to do to put the page in the new task mode? I need to simulate a build in behavior of $Action.Activity.NewTask. When I click on my custom button - I use the following URL now -  /apex/GIPSComposite?who_id={!Contact.Id}&tsk1={!User.Id}&tsk12=Completed&tsk4={!TODAY()}, I expect my page to open up and be ready for user's input, however the page opens blanks with no fields on it. What am I doing wrong?
Scott HungScott Hung
Hmm... That's hard to debug without getting into the gory details.  I'd start with standard VF debug techniques.  Add  debug output in your controller or add alerts to see what's executing in your VF page.  If you only get a blank page it has to be somewhere early in the cycle.  Take a look at the Order of Execution page:  https://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_lifecycle.htm
 
Mark SlavinMark Slavin
Thank you, Scott. I'll give it a try.