0

This question already has an answer here:

I have a requirement to hide custom button when condition is satisfied.On case I have person_role field.If the field is null then I need to hide custom button on vf page.

<apex:commandButton value="Confirm" action="{!Confirm}" />

if(case.Person_Role__c==NULL){
          ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'order cannot be created'));

Any help

marked as duplicate by Eric apex Apr 19 '17 at 21:40

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    there are plenty of questions that have an answer related to conditional rendering in visual force pages – glls Apr 19 '17 at 18:23
  • Use rendered attribute. – Mahmood Apr 19 '17 at 18:23
  • do we need to declare anything in the controller part.. – anjali Apr 19 '17 at 18:26
  • Yes, you need to have boolean property, and use that boolean property in the rendered attribute. The link posted in the other comments should give you a good start. – Mahmood Apr 19 '17 at 18:27
2

You can use rendered attribute in apex:commandButton like below:

<apex:commandButton value="Confirm" action="{!Confirm}"  rendered="{!ishide}"/>

Modified the class like below by using an extra boolean variable (ishide):

if(case.Person_Role__c==NULL){
 ishide = false;
         ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'order cannot be created'));
}

make sure you declare the ishide with {get;set;} and in constructor intialize the variable as ishide=true

1

It is very simple just do the following steps:

  1. create one boolean variable say hidebtn and make the value false
  2. Make it true in the below code:

    if(case.Person_Role__c==NULL){
        hidebtn = true;
        ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'order cannot be created'));
    }
    

Put the variable in button rendered condition.

<apex:commandButton value="Confirm" action="{!Confirm}" rendered={!NOT(hidebtn)}/>

It will solve your purpose.

  • 1
    then accept the ans so other can find it useful. – Avijit Das Apr 19 '17 at 18:36

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