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
RICARDO PALMARICARDO PALMA 

Disable or Enable a custom button.

Hi,
I have a custom visualforce page and I want a to enable a button only after all the required fields have been entered.
Any example code?
Thanks. 
Onur Kaya 9Onur Kaya 9
Hi Ricardo,

Check this example first, this is how you can create VF button (One of the ways)

http://sfdc.arrowpointe.com/2009/01/08/invoke-apex-from-a-custom-button-using-a-visualforce-page/
 
public class VFController {
 
    // Constructor - this only really matters if the autoRun function doesn't work right
    private final Opportunity o;
    public VFController(ApexPages.StandardController stdController) {
        this.o = (Opportunity)stdController.getRecord();
    }
     
    // Code we will invoke on page load.
    public PageReference autoRun() {
 
        String theId = ApexPages.currentPage().getParameters().get('id');
       
        //Added by Onur - Begin
        Opportunity opp = [Select Name, Custom1__c, Custom2__c From Opportunithy Where Id =: theId];
 
        if (theId == null || opp.Name == null || opp.Custom1__c == null || opp.Custom2__c == null) {
            // Display the Visualforce page's content if no Id is passed over
            return null;
        }
// Onur Kaya - END
 
        for (Opportunity o:[select id, name, etc from Opportunity where id =:theId]) {
            // Do all the dirty work we need the code to do
        }
 
        // Redirect the user back to the original page
        PageReference pageRef = new PageReference('/' + theId);
        pageRef.setRedirect(true);
        return pageRef;
 
    }
 
}