1

i need to pass custom field value Email_id__c from one custom object Registration__c to another FeedbackFrom__c both objects are having different VF Pages how can i achieve this.

My Apex code is:

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

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

My 1st VF Page:

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

        <apex:form >
            <html>
  <head>
  <title>RegistrationPage</title>

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

       div.btnGroup1{
      text-align:right;margin-top:-24px;margin-right:100px;
       }
           div.btnGroup2{
      text-align:center;margin-top:30px;margin-right:550px;padding:8px*20px;
       }

   </style>
   </head>
    </html>
        <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 /> 
         </apex:pageBlockSection>


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



    </apex:pageBlock>
    </apex:form>
</apex:page>

My 2nd VF Page:

<apex:page standardController="FeedbackFrom__c" extensions="SampleEmail" showheader="False" sidebar="False">
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
    <script>
    $(document).ready(function(){
        $(".bPageBlock").css("background-color","papayawhip");
        $(".bPageBlock").css("border-color","papayawhip");
    });
    </script>
    <style>
   body{ background-color:papayawhip;}
</style>
<apex:form > 
<html>
<head>
<title>Questionnaire8</title>
 <style>
       div.btnGroup{
      text-align: center;margin-top:125px;margin-right:250px;padding:8px*20px;
       }



     body .bPageBlock .pbHeader {
    background-color: Green; 
}
 </style>
</head>

    <body>

        <apex:commandButton action="{!email}" value="Registered email" styleClass="buttonStyle"  style="background:thistle ;width:130px;height:25px;font-size: 14px"/>


        </body>
    </html>
    </apex:form>
   </apex:page>

But Am getting Invalid conversion from runtime type FeedbackFrom__c to Registration__c Error. Please Help me out from this issue

1 Answer 1

1

The error that you are getting,

Invalid conversion from runtime type FeedbackFrom__c to Registration__c Error

is due to :

You have 2 separate standard controller on 2 pages, but use same extension in both of them. So when you redirect to the next page, it will re-initialize the extension instance, calling the constructor again. Now in your constructor, you have reg = (Registration__c)Controller.getRecord(); but when you are in the 2nd page, your standard controller contains a record of FeedbackFrom__c, not Registration__c, hence the conversion error.

As far as passing parameter is concerned, you have the option to pass it via URL.

On your save function, where you are redirecting to page 2, add the parameters:

return new PageReference('/apex/Page2?param1='+emailId);

Retrieve the parameter value in Sample's constructor,

if(ApexPages.currentPage().getParameters().get('param1') != null)
{
     emailId = ApexPages.currentPage().getParameters().get('param1');
}
2
  • how can i pass this field to Next page...?
    – Anjaan
    Apr 5, 2017 at 7:19
  • Updated my answer with it. Apr 5, 2017 at 7:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .