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
alliswellalliswell 

VF Page iwith custom controller to be used as button

Hi All,

 

Since I can't use recordsetVar for custom controller, how can i use a visualforce page (using custom controller) as a list button?

 

Thank you in advance!!

 

 

souvik9086souvik9086

Hello,

 

Create your list in the custom controller and then display that through table in vf page like below

 

Controller

public class YourController{

public List<Account> accList{get;set;}

public YourController(){

accList = new List<Account>();

accList = [SELECT id,name from Account];

}

}

 

Visualforce

<apex:pageblochktable value="{!accList}" var="acc">

<apex:column headerValue="Account Name">
<apex:outputText value="{!acc.name}"/>
</apex:column>

</apex:pageblochktable>

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks

 

alliswellalliswell

souvik9086,

 

Really appreciate the time you have given here. Unfortunately, I don't think I communicated the problem in hand properly.

 

My question is

 

How can we use Visualforce Page(with custom controller and not the standard controller) as a Button in List view(as a button appearing in the Related list)?

 

Thanks!!

souvik9086souvik9086

To add a custom button in the relatedlist of an object you have to use standard controller in that page and you can use extensions to give your custom controller name there and write your custom logic all in the custom controller.

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks

Yoganand GadekarYoganand Gadekar

So as to overide the custom object related list button of that object you will have to use standard controller of that object, and you can use recordsetvar(have tested it)... for custom functionality write extenssion...

 

 for example if my custom object ai name is Hostel__c:

<apex:page standardController="Hostel__c" recordsetVar="rt">

 

This page will be available for overiding the realetd list button of custom object

 

Hit kudos and mark as answer if it helps.

Jerun JoseJerun Jose
If you must use a custom controller in your code, you could have the custom button point to a URL and you could have the URL value as

/apex/VFPageName?id='recordID'

In the controller then you could get the ID parameter and then query for the list of records.
alliswellalliswell

Thank you all for insights.

 

For my particular case, standard controller with extension w/ standardsetcontroller worked.

 

Thank you again!

Vikas KewalramaniVikas Kewalramani
Hi Jerun, i tried what you said and it shows URL expired, i think there must be another way out,,,,,