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
shephalishephali 

i want to insert data as well as fetch and sent dat data to another VF page on button click.both VF page sharing the same controller

i want to insert data as well as fetch and sent dat data to another VF page on button click.both VF pages are sharing the same controller
bob_buzzardbob_buzzard
As both pages are using the same controller, as long as you don't use setRedirect=true when generating the page reference from the button click, the controller instance will be retained across the pages and the second page will have access to all properties/variables created by the first.
shephalishephali
Hello bob_buzzard,
I am using following code for insertion but now on clicking save button i want to select one field that i have just inserted and send it to another VF page.
///apex class:
Public class MyExtension
{
 Mobile_Agent__c agent;
public MyExtension(ApexPages.StandardController con)
{
 agent=(Mobile_Agent__c)con.getRecord();

public PageReference save()
{
if(agent!=null)
insert agent; 
PageReference pr=new PageReference('/apex/v5');
pr.setRedirect(true);
return pr;
}
}
////VF page
<apex:page sidebar="false" standardController="Mobile_Agent__c" extensions="MyExtension">
    <apex:form >
    <apex:pageBlock title="Register Agent mobile">
        <apex:pageBlockSection >
             <apex:inputfield value="{! Mobile_Agent__c.Name }" /> <br/>
            <apex:inputfield value="{! Mobile_Agent__c.Last_Name__c }" /> <br/>
            <apex:inputfield value="{! Mobile_Agent__c.Device_Phone__c}" /> <br/>
            <apex:inputfield value="{! Mobile_Agent__c.Subscriber_ID__c}" />
        </apex:pageBlockSection>    
 <p>  <apex:commandButton action="{!save}" value="Register Agent mobile"/></p>
   
    </apex:pageBlock>
    </apex:form>
</apex:page>
bob_buzzardbob_buzzard
You don't need to send it anything. Just remove the setRedirect(true) from the page reference and the second VF page will be able to see the agent property.