1

I'm looking for a way to hide a button depending on the field value.

My goal here is that the button will be hidden IF Product_Family__c is EQUAL to "Services".

Apex

public Opportunity currentOpportunity {get; set;}
public void getOppty(){
        Opportunity opp = [SELECT Id, Product_Family__c FROM Opportunity WHERE Id=: currentOpportunity.Id];  

    }

VF

            <apex:commandButton styleClass="slds-button slds-button_neutral slds-m-top_large"
                                value="Add Item" action="{!addItemRow}" reRender="tableId" status="status" render="{!getOppty}">
            </apex:commandButton>

I'm still missing the criteria for the APEX, any ideas?

Any kind of help is much appreciated!

  • What does the rest of your VF page look like? Is it using the opportunity standard controller? – Nick Cook Aug 21 at 6:53
  • @NickCook Yes, it's using the opportunity standard controller – Naofumi Kun Aug 21 at 6:55
1

You just need to use the rendered parameter on the apex:commanButton element.

e.g.

<apex:commandButton rendered="{!Opportunity.Product_Family__c != 'Services'}" value="Add Item" action="{!addItemRow}" reRender="tableId" status="status" />

You don't need any apex code if all you want to do is control whether the buttons is displayed on page load.

  • I overthink. It's so simple thank you very much! – Naofumi Kun Aug 21 at 7:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.