Friday, May 6, 2016

Formula Expression is required on the action attributes

This issue usually comes when your preparing any kind of PageReference in controller methods.

Snippet to produce Issue
public PageReference cancel()
{
 system.debug('entered inside cancel...'+td);
 if(Apexpages.currentPage().getParameters().get('id')==null)
 {
   PageReference p = new PageReference ('a4H/o').setRedirect(true);
   return p;
 }
 PageReference p = new PageReference ('/apex/DetailPage?id='+td.id+'mode=view');
 p.setRedirect(true);
 return p;
}
    
Root Cause for the Issue

This is because of the missing '/' and '&' symbols in the final url which is build by using PageReference .
  • In the above snippet '/' is missing before a4H/o 
  • '&' is missing before mode=view in pageReference
WorkAround Solution 

Please add those 2 special charcters in the code so it will be work as expected
public PageReference cancel()
{
 system.debug('entered inside cancel...'+td);
 if(Apexpages.currentPage().getParameters().get('id')==null)
 {
   PageReference p = new PageReference ('/a4H/o').setRedirect(true);
   return p;
 }
 PageReference p = new PageReference ('/apex/DetailPage?id='+td.id+'&mode=view');
 p.setRedirect(true);
 return p;
}
    

Thanks for visiting....Enjoy.

Action Status is not working for Command Buttons or Ajax Functions

Action Status:
   Action Status is an Ajax function which will be used to show the status of an action that is happening in background.

Example

1.Click on Button just showing like an Loading Image
2.Click on any command link showing some status Please wait loading...

Issue:
Recently I come across an issue like when I click on command button I want to show some status Image.I have implemented status message (Using Preloaders)and I'm passing same to command button but still it's not working.

Sample Page
 <apex:page standardController="Account" extenstions="AccountEtn">  
     <apex:form id="formId">  
       <apex:actionstatus id="attachingStatus" >  
          <apex:facet name="start">  
              <div class="waitingSearchDiv" id="el_loading" style="background-color: white; height:90%;opacity:0.65;width:100%;">  
                  <div class="waitingHolder" >  
                       <img class="waitingImage" src="{!$Resource.Loading}" title="Please Wait..." />  
                          <font color="Red"><b>Please wait we are loading....</b></font>   
                  </div>  
              </div>  
          </apex:facet>  
       </apex:actionstatus>  
       <apex:pageBlock id="pbid1" >  
            <apex:pageBlockButtons >  
                <apex:commandButton value="Save" action="{!save}" id="saveButton" status="attachingStatus" />  
                 <apex:commandButton value="Cancel" action="{!cance}" id="cancelButton" status="attachingStatus" />  
            </apex:pageBlockButtons>  
        </apex:pageBlock>  
      </apex:form>  
 </apex:page>  

Above sample code I have written in my page and when I click on any command buttons nothing is happening..It's not showing any status it's simply executing the logic .

Reason for the Issue

Some times if your command button not specifying any reRender attribute in your command button it will not show action status

Work Around Solution

Please include the reRender attrbute as part of your command button then it will work.

 <apex:page standardController="Account" extenstions="AccountEtn">  
     <apex:form id="formId">  
       <apex:actionstatus id="attachingStatus" >  
          <apex:facet name="start">  
              <div class="waitingSearchDiv" id="el_loading" style="background-color: white; height:90%;opacity:0.65;width:100%;">  
                  <div class="waitingHolder" >  
                       <img class="waitingImage" src="{!$Resource.Loading}" title="Please Wait..." />  
                          <font color="Red"><b>Please wait we are loading....</b></font>   
                  </div>  
              </div>  
          </apex:facet>  
       </apex:actionstatus>  
       <apex:pageBlock id="pbid1" >  
            <apex:pageBlockButtons >  
               <apex:commandButton reRender="pbid1" value="Save" action="{!save}" id="saveButton" status="attachingStatus" />  
               <apex:commandButton reRender="pbid1" value="Cancel" action="{!cance}" id="cancelButton" status="attachingStatus" />  
            </apex:pageBlockButtons>  
        </apex:pageBlock>  
      </apex:form>  
 </apex:page>  

Thanks for Visiting.....Enjoy!