2

I am opening one VF page on click of edit fo lis view of particular object. Now I want to get the id of that particular record which I edited. I am writing this code but its throwing this error.

Cyclical server-side forwards detected: /apex/CasePopulate

VF Code

<apex:page standardController="Case_Accession__c" extensions="ExtentionController1" action="{!pageredir}"  >
<apex:form >
<apex:pageBlock >
 <!-- Begin Default Content REMOVE THIS -->
<h1>Congratulations</h1>
This is your new Page
<!-- End Default Content REMOVE THIS -->
<apex:inputText value="{!TestEditSpecimenID }"/>
</apex:pageBlock>
  </apex:form>
</apex:page>

Apex Code

public class ExtentionController1
{
     public String var {get;set;}
     public string TestEditSpecimenID {get;set;}
 public ExtentionController1(ApexPages.StandardController controller)
 {}
 public Pagereference pageredir()
 {
  var= ApexPages.currentPage().getParameters().get('Id');
       if(var!=null)
       {
         TestEditSpecimenID = var;
         Pagereference newpage = new Pagereference ('/apex/CasePopulate');
          //Pagereference newpage =Page.Accession;
        return newpage;
       }
        else
       {
         //Pagereference newpage =Page.Accession;
         return null;
       }
   }
}

One more thing please I want to show the ID of reord into " "

Thanks in advance Raman

1

Use with StandardController getId method

var = controller.getId();

5
  • Can you please tell me in detail, and which controller is this ????
    – Raman
    Jul 22 '13 at 5:45
  • ApexPages.StandardController Jul 22 '13 at 5:46
  • Sorry But I am not getting you Shimshon
    – Raman
    Jul 22 '13 at 5:54
  • @Raman what is the first parameter of the constructor... Jul 22 '13 at 6:19
  • @ShimshonKorits It may help if you give some more explination and detail on how this can be integrated and used in the way asked. Jul 22 '13 at 6:52
0

Since you're using a controller extension, it takes a reference to a StandardController as the sole parameter in its constructor:

public class ExtentionController1
{
    public String var {get;set;}
    public string TestEditSpecimenID {get;set;}

    public ExtentionController1(ApexPages.StandardController controller)
    {}

You can use that controller to get the record selected by the user. The standard controller for the page specified in the <apex:page> tag is the Case_Accession__c controller, so you can save a reference to the record in a member variable in your class by casting the object returned by the StandardController's getRecord() method:

public class ExtentionController1
{
    public String var {get;set;}
    public string TestEditSpecimenID {get;set;}
    public Case_Accession__c caseAccession {get;set;}

    public ExtentionController1(ApexPages.StandardController controller)
    {
        // the cast
        caseAsccession = (Case_Accession__c)controller.getRecord();
    }

Now you can access the Id using caseAccession.Id or any other field that's being referenced in the Visualforce page (the controller only loads the fields used).

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.