You need to sign in to do that
Don't have an account?
AQ
Calling Visualforce page from Custom List Button
I am trying to call a Visualforce page from a custom list button. I have done this successfully from a detail page button by creating a page using a standard controller for the detail object, selecting Visualforce page as the content source and then picking the page I wanted from the pull down list for content.
However, I can't seem to get this to work for a list button. I pick the list button option on the custom button or link page, and pick visualforce page for the content source, but I don't get my visualforce page to appear in the content pull down list.
Is there something I'm doing wrong?
As an adjunct question, should I be using the standard controller for the detail object being displayed at the top of the page or for the objects being referenced in the list (in the case I'm working on now, the objects in the list are the same object as the detail object and reference back to the detail object)?
I understand that one of the benefits of using a visualforce page in this manner is that the id for the detail object is automatically passed to the visualforce page, thereby making data display easier on the detail page. If a visualforce page can be invoked from a list button, what object id is passed? That of the detail item at the top of the page?
Thanks in advance for your help,
Jeff
In order for a visual force page to appear while creating a custom button on a detail page, you must use the standard controller for the object that will appear on the detail page. Therefore, if you wanted to create a custom button from the contacts detail page, you must you the contact standard controller on the visual force page.
You can add a custom controller extension to contain all the various custom code and functionality you require.
The visual force documentation shows how to set this all up.
All Answers
Then if your page uses your object type as its standardController and your custom controller as an extension, it will show up as a selection.
Jeremy Kraybill
Austin, TX
Your page needs to make use of the standard list controller (standardcontroller with the recordSetVar attribute defined on your page). If you want to add custom logic to your page via an extension (which I assume you do, since you already have an Apex controller associated to your page) then you need to define it as an extension on your page, and then you'll need to add the constructor Jeremy mentioned.
The example in the documentaion isn't exactly what I'm trying to do. Assume that the opportunity list as shown in the documentation is linked to the account, I want to create a different "New Opportunity" button which will call my custom visualforce page. I don't want to override the existing button since I want to use the resultant code in a managed package.
On that custom visualforce page, I want to use something like <apex:detail/> to display the account detail information to serve as a reference while the user is inputting the new opportunity. Is there anyway with this technique to get access to the id for the parent (account) record?
I'm concerned about using a URL such as "/apex/mypage?accid={!Opportunity.AccountId}" with the custom button because I've read some posts here that suggest such usage will not work in a managed package. If this kind of link would work, then my problem is solved.
Any suggestions on how I might accomplish this?
AQ... Indeed usfing somethig like "/apex/mypage?accid={!Opportunity.AccountId}" doesnt work on a managed package...
Im having the same problem than AQ...
I made a custom button and placed it on the top of my Opp Layout and all i wanto to do is open a visualforce page with a parameter... If I want to do that on VF its as easy as writing:
<apex:outputLink value="{!$Page.myPage}"> Link Label
<apex:param name="oppId" value="{!opportunity.Id}"/> </apex:outputLink>
I tried using $Page on a OnClick javascript with no luck..
If anyone knows how to accomplish this I would really appreciate it if you share it with us...
Thanks in advance...
~ foe
There are two ways to do this
1. send it like, apex/mypage?id={!Opportunity.Id}". handle it in the extensions Controller's Constructor. Fetch the accountId in the constructor by querying the opportunity. and set it as a property. then u can use it in the page
2. If the above does not suits, the other way round is,take a simple s-control
something like
<html>
<head>
var accountId = '{!Opportunity.AccountId} '
window.parent.location.href = "../apex/mypage?accId=" +accountId
</head>
</html>
I ended up reworking my code so that I always called a visual force page without parameters from the custom button. In doing so, the controller automatically inserts the id of the record on which the button had been placed. By using that id, I was able to eventually obtain the data that I needed. Sometimes that took some imagination, but I haven't found any situations yet that I couldn't solve.
A simple example goes something like this: I want to place a custom button on the opportunity screen that actually gets me to the account record, not the opportunity record. The controller will automatically place the id of the opportunity as a parameter on the visual force page that I call. I put an action="{!init}" statement into the the apex:page line which calls an init function in my controller extension. The "init" routine in my extension extracts the id from the page parameter, loads the opportunity to which the id refers, extracts the account id from the opportunity that was loaded and then loads the appropriate account
Sometimes it requires more manipulation to get where I want to go, but as I said above, I've been able to rework all my controllers so that I'm now able to use visual force pages for all my custom buttons. I suspect its possible that sooner or later this technique will fail, but for now its solved my problems.
Hi,
I need to add a new Custom button (name:HelloWorld) in "Contacts" detail page, while creating the button when I select the Content source as 'Visualforce Page' I am not able to see any Visualforce page in content list.
I added my own controller which uses the uses apex generated by WSDL to get the data from the SOAP service.
Below is the code for custom controller & custom page.
Created Visrualforce page called CustomPage
While creating the custom button on 'Contacts' I am not able to see this CustomPage in the content when I select the Visualforce Page
Can any please help me out how to use the Custom Controller for getting data from external SOAP service.
Thanks
In order for a visual force page to appear while creating a custom button on a detail page, you must use the standard controller for the object that will appear on the detail page. Therefore, if you wanted to create a custom button from the contacts detail page, you must you the contact standard controller on the visual force page.
You can add a custom controller extension to contain all the various custom code and functionality you require.
The visual force documentation shows how to set this all up.
Thank you AQ
Thanks Jill - that works a treat.
cheers,
manu
Just a note in case this can save someone some time. If you're going to access getSelected() method on your StandardSetController, you must explicitly cast the sObject to the type you're expecting. getSelected() returns a generic sObject.
public MyListController(ApexPages.StandardSetController stdSetController) { // if you wish, do something with stdSetController.getSelected() // if your set is typed as (for example) Opportunity, do this: List<Opportunity> myOppList = (List<Opportunity>)stdSetController.getSelected(); }
Hi folks - I'm attempting to implement this method to create a List View button that gets the selected rows & pass them to another method, but I'm getting an error :
Are these buttons supposed to return a page reference? If so, how to I get the list view ID to return to the page after the controller method completes?
My List View button points to this VF page:
Which call this controller when clicked:
I've tried other combo's too - putting the code in the set controller init and calling init, trying to return a different page ref, trying to return no pageref, but haven't hit anything that works yet :(
I should add that in all of my iterations, the debug logs show all the code runs, but nothing actually happens (methods aren't committed?).
so this thread help me out of a jam
before i was relying on query string info and now i have to change that logic
but overall, im in a better place thanks to this thread
:smileyhappy:
I have a visual page with the standard controller set to my custom object: Contract Review
I want to create a Custom List button on the Contract Review related list in opportunities. However, when creating the button the content field is blank and there is no option to select my ContractReview VF page.
Any ideas?
for lists, you need a recordset var defined in your VF page
Thank you ,easy when you know how. I have another question my Custom object (Contract_Review__c) has a master-detail relationship with Opportunity and on my visualforce page I want to have an output field which displays the opportunity name. This value is not populating by using:
<apex:outputField value="{!Contract_Review__c.Opportunity__c}"/> , I've tried many variation but just can't seem to get it right. Any guidance would be a great help.
@ James76 : try to use this:
<apex:outputField value="{!Contract_Review__c.Opportunity__r.Name}"/>
"{!Contract_Review__c.Opportunity__c}" will just refer to the Opportunity ID - you need to use "Opportunity__r" to refer to the related Opportunity object itself.
Is it possible to create STANDARD LIST CONTROLLER for TASK ?
Thanks a lot ! that was useful.
"The visual force documentation shows how to set this all up. " is it possible to explain with an example ? i tired but i lost some where (infact every where).
Thanks a lot ! that was useful.
"The visual force documentation shows how to set this all up. " is it possible to explain with an example ? i tired but i lost some where (infact every where).