0

I am new to SFDC. I have two Custom Objects both are having different VF Pages in my 1st custom object Registration__c I have one field Email_id__c. Every time if user enters value on Email field it should be Auto populate on my 2nd Custom Object FeedbackFrom__c Registered Email Field.

My Apex Coding is:

public class CurrentRecordIdDemoController{
public String currentRecordId {get;set;}
public String parameterValue {get;set;}
public Registration__c Reg{get;set;}

    public CurrentRecordIdDemoController(ApexPages.StandardController controller) {
        currentRecordId  = ApexPages.CurrentPage().getparameters().get('id');
        Reg = [select id ,Email_id__c from Registration__c where id =: currentRecordId ];
        parameterValue = ApexPages.CurrentPage().getparameters().get('nameParam');
    }
}

My Vf Coding is:

<apex:page standardController="Registration__c" extensions="CurrentRecordIdDemoController">
  <apex:form >
    <apex:pageBlock >
        <apex:pageBlockSection title="Your Email" collapsible="false">
            <apex:outputField value="{!Reg.Email_id__c}"/>
          </apex:pageBlockSection>

        <apex:pageBlockSection title="Testing parameter" collapsible="false">
            Name is <b>{!parameterValue}</b>
        </apex:pageBlockSection>

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

please any help me out from this issue.

4
  • 1
    are you passing the id in url like.. /apex/pageName?id=001212121 something ??? .. ApexPages.CurrentPage().getparameters().get('id') this line of code will get the id from url
    – Ratan Paul
    Apr 3, 2017 at 5:49
  • @Ronald I tried your code and it works fine. The only problem could be the URL parameters which you're passing. Apr 3, 2017 at 6:07
  • i have two different pages for each Custom object i need to pass value From Cus_Obj 1 to Cus_Obj 2 how can i achieve this..???
    – Anjaan
    Apr 3, 2017 at 6:11
  • @Ronald Then you should have method like this: PageReference pageRef = new PageReference('/apex/vf_page_name?id=recordId&nameParam=value); pageRef.setRedirect(true); return pageRef;. This will return control to your page. Apr 3, 2017 at 6:14

4 Answers 4

1

Since you are using Controller extension then you don't need to use separate query to get the record.

Just use StandardController.getRecord() method like this.

public Registration__c Reg{get;set;}
private Registration__c RegList;

public CurrentRecordIdDemoController(ApexPages.StandardController controller) {
    this.Reg = (Registration__c)controller.getRecord();
    parameterValue = ApexPages.CurrentPage().getparameters().get('nameParam');
}
0

Because query will return in List.Although only one row data retrieved , it still in List.

To be safe use

List<Registration__c> regList =[select id ,Email_id__c from Registration__c where id =: currentRecordId ];

Reg =regList[0];

Please refer to this link : Error, "List has no rows for assignment to SObject"

0

Check for following two things:-

  1. The visualforce page url has paramter named `id'
  2. If Id is present then make sure you have records in the database related to the Id

Here is the way to prevent from exception issue. Always use List<SomeObject__x>. Ex:

public Registration__c Reg{get;set;}
private Registration__c RegList;

public CurrentRecordIdDemoController(ApexPages.StandardController controller) {
        currentRecordId  = ApexPages.CurrentPage().getparameters().get('id');
        RegList = [select id ,Email_id__c from Registration__c where id =: currentRecordId ];
        if(RegList.size()>0)
        {
           Reg =  RegList[0];  
        }
        parameterValue = ApexPages.CurrentPage().getparameters().get('nameParam');
    }

If you are opening the page from detail page/related list button click. You can directly get the If by

currentRecordId  = controller.getId();
0


You are getting this error because the code is not getting any current id from ApexPages.CurrentPage().getparameters().get('id'); this line of code.

you can use the constructor to use the StandardController.getRecord()

Try the below code:

public class CurrentRecordIdDemoController{
public String currentRecordId{get;set;}
public String parameterValue{get;set;}
public Registration__c Reg{get;set;}
public CurrentRecordIdDemoController(){
  currentRecordId =ApexPages.CurrentPage().getparameters().get('id');
  Reg =[select id,Email_id__c from Registration__c where id =: currentRecordId ];
}
public CurrentRecordIdDemoController(ApexPages.StandardController controller){
   parameterValue =ApexPages.CurrentPage().getparameters().get('nameParam');
  }
}

To get the name from the current record:

Registration__c var =(Registration__c)controller.getRecord();
parameterValue =ApexPages.CurrentPage().getparameters().get('nameParam');

Regards,
Akshay

You must log in to answer this question.

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