+ Start a Discussion
NikunjVadiNikunjVadi 

get record id of saved data for page reference

I want to save current record and want id of that saved record to pass through to page reference . My controller is:
public HomeEvaluationController (ApexPages.StandardController sc)
      {
        myCustomObject = (HomeEvaluation__c) sc.getRecord();
        controller=sc;
     
      }
public PageReference New_form_save()
        {
         controller.save();

           pageid=myCustomObject.Id;
      
         Pagereference ref = new Pagereference('/apex/Ventilation_Ducting?id='+pageid);
         ref.setRedirect(true);
         return ref;
         }

I am getting null value in page id , please help me out
Best Answer chosen by NikunjVadi
Vatsal KothariVatsal Kothari
Hi Nikunj,

You can refer below code:
public HomeEvaluationController (ApexPages.StandardController sc)
{
	this.controller = sc;
	myCustomObject = (HomeEvaluation__c) sc.getRecord();	
}

public PageReference New_form_save()
{
	PageReference ret = controller.save();
	
	Id pageid = controller.getId();
	
	Pagereference ref = new Pagereference('/apex/Ventilation_Ducting?id='+pageid);
	ref.setRedirect(true);
	return ref;
}
If this solves your problem, kindly mark it as the best answer.

Thanks,
Vatsal

All Answers

Vatsal KothariVatsal Kothari
Hi Nikunj,

You can refer below code:
public HomeEvaluationController (ApexPages.StandardController sc)
{
	this.controller = sc;
	myCustomObject = (HomeEvaluation__c) sc.getRecord();	
}

public PageReference New_form_save()
{
	PageReference ret = controller.save();
	
	Id pageid = controller.getId();
	
	Pagereference ref = new Pagereference('/apex/Ventilation_Ducting?id='+pageid);
	ref.setRedirect(true);
	return ref;
}
If this solves your problem, kindly mark it as the best answer.

Thanks,
Vatsal
This was selected as the best answer
NikunjVadiNikunjVadi
Thanks :)