+ Start a Discussion
Jeanne Jobes 1Jeanne Jobes 1 

Visualforce page using a custom controller is not available when creating a new detail page button

public class StockListController {
    
public List<Stock_Item__c> getStockItems() {
    
    List<Stock_Item__c> results = Database.query(
        'SELECT ID, Item_Name__c, Item_Stock_is_Low__c, Minimum_Stock_Level__c, Stock_on_Hand__c ' +
        'FROM Stock_Item__c ' +
        'WHERE Item_Stock_is_Low__c = true'
    );
    return results;
}
}    



<apex:page lightningStyleSheets="true" Controller="StockListController">
    <apex:form>
        <apex:pageBlock title="Low Stock Items" id="stock_item_list">
            
            <!-- Stock Item List goes here -->
            <apex:pageBlockTable value="{! StockItems }" var="si">
                <apex:column value="{! si.ID }"/>
                <apex:column value="{! si.Item_Name__c }"/>
                <apex:column value="{! si.Item_Stock_is_Low__c }"/>
                <apex:column value="{! si.Minimum_Stock_Level__c }"/>
                <apex:column value="{! si.Stock_on_Hand__c }"/>
    
</apex:pageBlockTable>
            
        </apex:pageBlock>
    </apex:form>
</apex:page>

User-added image
Prady01Prady01
Hi there, when you are trying to make a custom button on the object then you will have to mandatorily use standard controller and extensions in your VF page or else your page will not show up under the object.

Example imagine I want to add a custom VF page on Account then below is how my VF page should look like.
 
<apex:page lightningStyleSheets="true" extensions="StockListController" standardController ="Account">
// your code goes here.
</apex:page>

Hope this helps!
Prady01