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
Ryan PatRyan Pat 

vf page hide button

I have one visualforce page and based on opportunity stage = closed won and if industry is blank it is throw error message that please select industy but in the vf page at the bottom there are 2 buttons but when this error message come i do not want to show submit button i want to hide that button how can i complete this ?
Here is my code
<apex:page standardcontroller="Opportunity" extensions="OpportunityApprovalControllerExtension">
    
    <apex:Form >
        <apex:PageBlock mode="view" title="Approval Submission Details">
            <apex:messages />
            <apex:PageBlockButtons location="bottom">
                <apex:commandButton value="Submit" action="{!SubmitForApproval2}"  rendered="{!ShowSubmitButton}" />  
                <apex:commandButton value="Return to Opportunity" action="{!ReturnToOpp}" />
            </apex:PageBlockButtons>
        </apex:PageBlock>
    </apex:Form>
    
</apex:page>

 
Best Answer chosen by Ryan Pat
Khan AnasKhan Anas (Salesforce Developers) 
Hi Mitali,

Greetings to you!

Try this:
<apex:page standardcontroller="Opportunity" extensions="OpportunityApprovalControllerExtension">

<style type="text/css">
.buttonDiv {
	padding-left: 115px; /*attempts to indent the button to better align within the standard page layout*/
	display: {!IF( Opportunity.StageName = 'Closed Won', 'none', '')}; /*controls whether the div tag is displayed*/
}
</style>

    <apex:Form >
        <apex:PageBlock mode="view" title="Approval Submission Details">
            <apex:messages />
            <apex:PageBlockButtons location="bottom">
                <div class="buttonDiv">
                     <apex:commandButton value="Submit" action="{!SubmitForApproval2}"  />  
                </div>
                <apex:commandButton value="Return to Opportunity" action="{!ReturnToOpp}" />
            </apex:PageBlockButtons>
        </apex:PageBlock>
    </apex:Form>

</apex:page>

Please refer to the below links which might help you further with the above requirement.

http://www.infallibletechie.com/2013/04/hide-and-show-example-using-apex-in.html

http://www.interactiveties.com/blog/2012/visualforce-dynamic-buttons.php

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas

All Answers

Khan AnasKhan Anas (Salesforce Developers) 
Hi Mitali,

Greetings to you!

Try this:
<apex:page standardcontroller="Opportunity" extensions="OpportunityApprovalControllerExtension">

<style type="text/css">
.buttonDiv {
	padding-left: 115px; /*attempts to indent the button to better align within the standard page layout*/
	display: {!IF( Opportunity.StageName = 'Closed Won', 'none', '')}; /*controls whether the div tag is displayed*/
}
</style>

    <apex:Form >
        <apex:PageBlock mode="view" title="Approval Submission Details">
            <apex:messages />
            <apex:PageBlockButtons location="bottom">
                <div class="buttonDiv">
                     <apex:commandButton value="Submit" action="{!SubmitForApproval2}"  />  
                </div>
                <apex:commandButton value="Return to Opportunity" action="{!ReturnToOpp}" />
            </apex:PageBlockButtons>
        </apex:PageBlock>
    </apex:Form>

</apex:page>

Please refer to the below links which might help you further with the above requirement.

http://www.infallibletechie.com/2013/04/hide-and-show-example-using-apex-in.html

http://www.interactiveties.com/blog/2012/visualforce-dynamic-buttons.php

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
This was selected as the best answer
Ryan PatRyan Pat
Hi Khan Thank you for reply for this condition it is working but when it meet this condition and for other logic 2 button is not visible correctly you can see the screenshot .User-added image

How can i fix this issue??
Ryan PatRyan Pat
Hey Khan Anas   help me in this bathc class :
I have one object called CPM which has couple of fields one is user field which has a lookup with user object and second one is week number which is a formula field it will show which week is going on based on Todays date.
2. On opportunity object i have 2 field one is sub date it is a date field and other is current week which is a formula field it will show current week number based on opportunity sub date .
Now the requirement is based on CPM object record user and week number field it will go to all opportunity which is created this year and sub date is not blank and on opp current week is same and update CPM Field .
Here is a batch class it is working currectly but some one check and optimized this code as much as possible with bulkify also :
global class CPMBatch implements Database.Batchable<sObject> ,Database.Stateful
{
 list< CPM__c > lstToUpdate = new list <CPM__c>();
  global Database.QueryLocator start(Database.BatchableContext BC) {
            
            list <string> stValue = new list <string>();
            list <CPM_Team_List__mdt > LstSaleTeam = [select id , User_Name__c from CPM_Team_List__mdt ];
            for(CPM_Team_List__mdt  st : LstSaleTeam)
            {
                stValue.add(st.User_Name__c);
                
            }
                
                String query = 'SELECT Id,Name, Week_Number__c , User__c , User_Name__c from CPM__c  where Week_Number__c != null and  User_Name__c IN : stValue  ';
          
            
            return Database.getQueryLocator(query);
    }

    global void execute(Database.BatchableContext BC, List< CPM__c > scope){
          String  uname ;
          Decimal weeknum ; 
          ID  CPMId;
         for (CPM_MANAGEMENT__c mtscope : scope) 
           {
                      uname = mtscope.User_Name__c ;
                      weeknum = mtscope.Week_Number__c ;
                    CPMId = mtscope.id;
                      
           }
           
           
         list <opportunity > opp = [select id , name , Owner_Name__c from opportunity 
                                                               where sub_Date__c != null 
                                                                     and Current_Week__c =: weeknum  
                                                                     and Owner_Name__c =: uname ]  ; 
                         
                              
         
             for(CPM_MANAGEMENT__c Ctam : scope )
             {
             
                Ctam.id = CPMId ;
                Ctam.CPM_Updated_Goal__c = opp.size();
                lstToUpdate.add(Ctam);
               
         
             }
         if(lstToUpdate.size()>0)
            {
            database.update(lstToUpdate,false);
            }
         }  
    global void finish(Database.BatchableContext BC)
    {
      
    }
}