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
sathishsfdcsathishsfdc 

calling apex command button twice results in the output

i have 3 command buttons with 3 different panels getting cases based on status.
If there are records in all Case Status then it is working fine but sometimes when there are no records in particular status
i need to hit the command button twice to get the details.
Any workaround for this??
<apex:commandButton value="1"   action="{!firstButton}"  />
<apex:commandButton value="2    action="{!secondButton}" />
 <apex:commandButton value="3"   action="{!thirdButton}" ;"/>


     <apex:outputPanel id="one" title="one" rendered="{!firstPanel}">

     ---retreivedata----
   
  </apex:output panel>
         <apex:outputPanel id="two" title="two" rendered="{!secondtPanel}">
        ---retreivedata----

     </apex:output panel>

         <apex:outputPanel id="three" title="three" rendered="{!fthirdPanel}">
     ---retreivedata----
     </apex:output panel>

     public void firstButton()
    {
      firstPanel=true;
      secondPanel= false;
       thirdPanel = false;
            customethod1();       
        }

    public void secondButton()
    {
      firstPanel=false;
      secondPanel=true;
       thirdPanel = false;
    customethod2();      
    }

   public void thirdButton()
    {
      firstPanel=false;
      secondPanel=false;
      thirdPanel = true;
      customethod3();
      
      }

 
James LoghryJames Loghry
There are a few blatant issues I see in your example:
  1. The rendered attribute needs to match exactly with the variable in your controller.  You mispelled "secondPanel" and "thirdPanel" in your rendered attribute above.
  2. The rendered attribute doesn't work very well with direct boolean variables.  My fix for this has been to use an IF statement shown in the example below.
  3. You likely want to use the "rerender" attribute on the commandButton, so that you only render the outputPanel(s) you need to.
<apex:commandButton value="1"   action="{!firstButton}"  rererender="parentOutputPanel" />
<apex:commandButton value="2    action="{!secondButton}" rererender="parentOutputPanel"  />
 <apex:commandButton value="3"   action="{!thirdButton}" rererender="parentOutputPanel" />


<!-- To rerender all the output panels for each commandButton, surround them with a parent output panel, give it an Id, and call the rerender attribute with that id from the command button -->
<apex:outputPanel id="parentOutputPanel">
     <apex:outputPanel id="one" title="one" rendered="{!IF(firstPanel,true,false)}">

     ---retreivedata----
   
  </apex:outputpanel>
         <apex:outputPanel id="two" title="two" rendered="{!IF(secondPanel,true,false)}">
        ---retreivedata----

     </apex:outputpanel>

         <apex:outputPanel id="three" title="three" rendered="{!IF(thirdPanel,true,false)}">
     ---retreivedata----
     </apex:outputpanel>

    </apex:outputPanel>

     public void firstButton()
    {
      firstPanel=true;
      secondPanel= false;
       thirdPanel = false;
            customethod1();       
        }

    public void secondButton()
    {
      firstPanel=false;
      secondPanel=true;
       thirdPanel = false;
    customethod2();      
    }

   public void thirdButton()
    {
      firstPanel=false;
      secondPanel=false;
      thirdPanel = true;
      customethod3();
      
      }

Give that a shot and see if it helps.  I know you're just pasting pseudo code, so there could be something in the actual code we're not seeing that is also causing your issue.  If you still have problems with it, please post the actual code next time.