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
M477M477 

Get standard controller ID from extension controller

Here is a reduced snippet of what I have so far:

 

<apex:page standardController="Case" extensions="NrtListController">
	<apex:param name="caseID" value="{!Case.id}"/>
	Standard CaseID: {!Case.id}
	Extension CaseID: {!CaseNrt}
</apex:page>

public class NrtListController {
	public NrtListController(ApexPages.StandardController controller) {}
	public String getCaseNrt(){
        	return System.currentPagereference().getParameters().get('caseID');
	}
}

 

 

This page returns

Standard CaseID: 500T0000002mTLlIAM

Extension CaseID:

 

How can I get the current objects ID to the extension controller (The extension CaseID should be the same as the Standard CaseID)?

 

Thanks,

Matt

 

Best Answer chosen by Admin (Salesforce Developers) 
Prajapati.LakhanPrajapati.Lakhan

Hi, I am not sure about your use case but document says you cannot use <apex:param> in this way. There is an easy way to get record id in extension controller. 

 

 

public class NrtListController {
    public string CaseNrt {get;set;}
	public NrtListController(ApexPages.StandardController controller) {
		 CaseNrt = (Case)controller.getRecord().id;
	}
	/*public String getCaseNrt(){
        	//return System.currentPagereference().getParameters().get('caseID');
	}*/
}

 

 

Thanks,

Lakhan

All Answers

Prajapati.LakhanPrajapati.Lakhan

Hi, I am not sure about your use case but document says you cannot use <apex:param> in this way. There is an easy way to get record id in extension controller. 

 

 

public class NrtListController {
    public string CaseNrt {get;set;}
	public NrtListController(ApexPages.StandardController controller) {
		 CaseNrt = (Case)controller.getRecord().id;
	}
	/*public String getCaseNrt(){
        	//return System.currentPagereference().getParameters().get('caseID');
	}*/
}

 

 

Thanks,

Lakhan

This was selected as the best answer
M477M477

Thanks,

 

The only change I had to make to that was

 

Case temp = (Case)controller.getRecord();
CaseNrt = temp.id;

 

else it would throw some error "Incompatible types since an instance of Id is never an instance of SOBJECT".

 

Vinit_KumarVinit_Kumar
Try below code :-

public class tabPanelExt {

  private final Account pos;
  public String id{get;set;}
  
  public tabPanelExt(ApexPages.StandardController controller)
  {
   
   id=(Account)stdController.getRecord().id;
   System.debug('***id***'+id);
  }
   
     public PageReference recordDetails()
     {
    PageReference requestPage = new pagereference('/apex/tabPanelPage?id='+id);
    System.debug('***requestPage ***'+requestPage );
    requestPage.setRedirect(true);
    return requestPage;

}

     

}


prasanth kumarprasanth kumar
hi amith,    thank you very much for code.  Actually i want to move the   current insert record into {!hello}    so i used this code in the above program. 
 
public accountcustomsave4()
  {
   // hello='jhjhjhj';
   hello=acc.name;
  }

Got this error. 

System.NullPointerException: Attempt to de-reference a null object 
Class.accountcustomsave4.<init>: line 28, column 1