+ Start a Discussion

Disable or Enable a custom button.

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?
Onur Kaya 9Onur Kaya 9
Hi Ricardo,

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

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);
        return pageRef;