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
Wayne Solomon 2016Wayne Solomon 2016 

Visualforce page redirect, http get and NO viewstate fush

Hi 

Is there a way to do a Visualforce page redirect, that performs a http get request on the form fields but DOES NOT flush the viewstate.

I'm trying to pass the record type to a single, new instance of a Visuaforce page.

Wayne
Best Answer chosen by Wayne Solomon 2016
Wayne Solomon 2016Wayne Solomon 2016
What I did to solve this was pass the recordtype as a parameter through the URL which works well

All Answers

Dilip_VDilip_V
Solomon,

Use 
  page.setRedirect(false);

For more info:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_System_PageReference_setRedirect.htm

Let me know if you have any issues.

mark it as best answer if it works.

Thanks. 
Wayne Solomon 2016Wayne Solomon 2016
Hi Thermo, I've tried that.  

What is happening is that all myinputField values are blank when they are supposed to have their field defaults set.
Dilip_VDilip_V

Ok.Have you tried Wizard based implementation.
Take a look at this
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_quick_start_wizard.htm

Thanks.
Wayne Solomon 2016Wayne Solomon 2016
Yes thanks.  It keeps the RecordType but all the other fields are blank on page 2 where they are suupposed to have default values
Dilip_VDilip_V

It would be better to share the VF and Controller.
So that I can understand it better.

Thanks.
Wayne Solomon 2016Wayne Solomon 2016

****Testing2017Dispatcher***
<apex:page standardController="Testing__c" extensions="Testing2017Extension">
<apex:form >
  <apex:commandButton value="Pepfar 15" action="{!redirect}"/>
</apex:form>
</apex:page>


****Controller method***
public PageReference redirect (){
        PageReference page = new Page Reference('/apex/Testing2017');
        this.testing.RecordTypeId = '0122C0000004J6O'; //testing is the sObject variable
        page.setRedirect(true);
        return testingPage;
    }
    
So, I have InputFields that have default values and when setRedirect(true) the values are populated but I have no record type populated.  When I run setRedirect(false), record type is populated but I have no default values.  It looks like the constuctor isn;'t running to iniliase the values of my inputFields.

****Constructor snippet***

public with sharing class Testing2017Extension {

    Testing__c testing = new Testing__c();
    public String selectedSite{get;set;}
    public String selectedVenue{get;set;}
    
    public Testing2017Extension (ApexPages.StandardController controller) {
        this.testing = (Testing__c)controller.getRecord();
        if (this.testing.id != null){
            this.selectedSite = this.testing.site__c;
            this.selectedVenue = this.testing.venue__c;
        }
        
    }
Wayne Solomon 2016Wayne Solomon 2016
I did some testing with the redirect method options.

1. Dispatcher page
User-added image

2. Redirect(false) on the first button press
User-added image


3. Redirect(true) on the second button press
User-added image
Dilip_VDilip_V
Everything is ok.Have you tried using setRedirect(false)?
Like this
public PageReference redirect (){
        PageReference page = new Page Reference('/apex/Testing2017');
        this.testing.RecordTypeId = '0122C0000004J6O'; //testing is the sObject variable
        page.setRedirect(false);
        return testingPage;
    }
Thsnks.

 
Wayne Solomon 2016Wayne Solomon 2016
What I did to solve this was pass the recordtype as a parameter through the URL which works well
This was selected as the best answer