Monday, July 14, 2014

Removing The ViewState Coming in URL.

Hi  EveryOne,

   Basically when we click on Button we will perform some action in controller and we will redirect to same using ApexPages.CurrentPage().Whenever we use that functionality some case we will get viewState in the URL.So workaround it to remove the ViewState and to form actual URL agian we need to de below thing.

ViewState URL:

    public PageReference yourmethodname(){
       //Your Logic
       pageReference pref = ApexPages.currentPage(); 
       Id id = pref.getParameters().get('Id');
       pref .getParameters().clear();
       pref .getParameters().put('Id', id);  
       pref .setRedirect(true);
       return pref;  

OutPut :'recordId'