+ Start a Discussion
Markey1Markey1 

Retain Query String Parameters on Page Refresh (return null;)

I have a site with a sidebar which populates the URL using the Query String Parameter. The issue is when the validation rules fire, the "return null;" in the custom controller "refreshes" the page and the query string parameter values are lost. Without the query string parametrs, the validation prevents the record from being saved. I may not be using the query string parameter correctly. Any links, suggestions, code examples etc. is much appreciated.

 

Visualforce Page Code which populates Query String Parameter:

<apex:outputlink value="{!URLFOR($Page.aeskisenroll) + '?RecordTypeId=012Q00000004So4'}">Enrollment</apex:outputlink>

Which makes the site URL look like this:

http://testing.somesite.cs3.force.com/aeskseenroll?RecordTypeId=012Q00000004So4

 When a validation rule fires, the URL incorrectly removes the query string parameters and looks like this:

http://testing.somesite.cs3.force.com/aeskseenroll

My Controller:

 

public class AESK_Enroll {
  
    
    /*Variables*/
    public AESK_Enrollment__c skEnroll;
    
    /*Controller*/
    /*ApexPages.StandardController controller;*/
    public AESK_Enroll(ApexPages.StandardController con){
        ApexPages.StandardController controller;         
        controller = con;        
        skEnroll = (AESK_Enrollment__c)controller.getRecord();                         

    }           

    /*Validate, save, and return page*/
    public PageReference save() {
    String pagert = ApexPages.currentPage().getParameters().get('RecordTypeId'); 
            try {             
            /*Issuer*/
            if(pagert == '012Q00000004So4') {
                skEnroll.RecordTypeId = '012Q00000004So4';
                skEnroll.AESK_Account_Type__c = 'Issuer';        
            }
            /*Merchant*/
            else if(pagert == '012Q00000004So9') {
                skEnroll.RecordTypeId = '012Q00000004So9';
                skEnroll.AESK_Account_Type__c = 'Merchant';        
            }     
            /*ACS Vendor*/             
            else if(pagert == '012Q00000004SoE') {
                skEnroll.RecordTypeId = '012Q00000004SoE';
                skEnroll.AESK_Account_Type__c = 'ACS Vendor';        
            }
            /*MPI Vendor*/        
            else if(pagert == '012Q00000004SoJ') {
                skEnroll.RecordTypeId = '012Q00000004SoJ';
                skEnroll.AESK_Account_Type__c = 'MPI Vendor';        
            }             
            else {
                return null;
            }                
           
            insert skEnroll;
        } 
        catch (DMLException e) {            
            ApexPages.addMessages(e);            
            return null;            
        }
        return page.aeskenrollconfirm; 
    }        
}

 

 

ngabraningabrani

I am including a code sample that reads the page paramter, and then passes those to the next page -

 

        PageReference currentPage = ApexPages.currentPage();    

        /* We first get the current page parameters and pass these to the next page */        
        Map<String,String> currentPageParameters = currentPage.getParameters();
        
        PageReference nextPage = new PageReference('/apex/NextPage');
        nextPage.getParameters().put('recordTypeId',currentPageParameters.get('recordTypeId'));

        return nextPage;