I have two VF pages i need to pass value from my 1 st VF input field to 2nd VF page using common custom controller.

this is My Apex Code;

public class Sample{
public Sample(ApexPages.StandardController controller)
public String Registration__c.Email_id__c  {get;set;}

    public void email() {
    System.debug('This is your registered email' + Registration__c.Email_id__c);

this is my Vf Code

<apex:page standardController="Registration__c" extensions="Sample"  showheader="False" sidebar="False">
    <apex:messages />

            <apex:form >

        <span style="display:block; margin:50px auto; text-align:Center;color:black;font-size:150%;">REGISTRATION PAGE - ONE TIME</span>


            <apex:pageBlock >
            <apex:pageBlockSection >  

            <apex:inputField required="true" value="{!Registration__c.Email_id__c}"/><br /> <br /> 
            <apex:inputField required="false" value="{!Registration__c.Mobile_number__c}"/><br /> <br /> 
            <apex:inputField required="false" value="{!Registration__c.Employee_number__c}"/>  <br /> <br /> 

             <div class="btnGroup2">  
             <apex:commandButton value="Save" action="{!save}" styleClass="buttonStyle" style="background:thistle ;width:110px;height:25px;font-size: 14px"/>


But i am getting Illegal variable declaration: Registration__c.Email_id__c Error how i can achieve this


You need to change variable initialization in your controller

public class Sample{
public Registration__c reg {get;set;}
public Sample(ApexPages.StandardController controller)
    reg  = (Registration__c)controller.getRecord();

    public void email() {
    System.debug('This is your registered email' + reg .Email_id__c);
    // now you can pass the email in parameter or can get that.

And as you have mention you are using same controller then you can make a wizard where all values in controller will be stored

PageReference acctPage = new PageReference('Your page URL);
 return acctPage;

You are trying to declare an sObject field as variable. This is not possible. Try the below code.

public class Sample{
    public Registration__c reg {get; set;}
    public String emailId {get; set;}
    public Sample(ApexPages.StandardController controller){
        reg = (Registration__c)Controller.getRecord();
        emailId = reg.Email_id__c;

    public void email() {
        System.debug('This is your registered email' + emailId);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.