Contents
Add the above returnPage () method to a new TheController (or whatever) class. It doesn’t even need a constructor. The class can look like this: Then from the Opportunity settings page go to Buttons and Links and create a new custom Visualforce button selecting the new page you just created. That should do it.
The Visualforce page shows up when I select Detail button, but when I try to create a list button, it doesn’t show up. So, to explain in more detail. The Visualforce page called testpage has Risk__c as the standard controller. I want to create a List Button, but I don’t have the option to select a visualforce page:
How to use JavaScript for Salesforce custom button?
The post on the developer boards that you’ve linked to shows the following javascript being used for the button: i.e. they’re using javascript to call a webservice method in the class they’ve defined in order to get the page reference.
How to redirect to a Visualforce page?
I found the post Managed Package Redirecting Problem on the Force.com Discussion Boards which implied it should be possible to use $Page to reference the Visualforce page in the URL. E.g. Error: Field $Page.MyExamplePage does not exist. Check spelling.
This is where JavaScript functions come in. A function is a block of code that runs when we tell it to. In this example, we will show how to run a function when a button is clicked. The first thing we’ll want to do is create the button and give it an id using HTML: Run Function .
When do you run a function in JavaScript?
In JavaScript, there are times when you need a block of code to just sit back, relax, and not run right when the page loads. This is where JavaScript functions come in. A function is a block of code that runs when we tell it to. In this example, we will show how to run a function when a button is clicked.