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 characters 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;
}
    

Please comment or write us if you have any queries/requirements.

Please follow,bookmark,subscribe this site to receive daily updates.

Facebook - https://www.facebook.com/ILoveCodingYou/?ref=bookmarks

Hope this helps you..Enjoy..!


No comments:

Post a Comment