You need to sign in to do that
Don't have an account?

Passing ID between two vf pages
I Am creating Child record(Home_Model__c) of account object Using this controller:
public class HomeModelController {
Apexpages.StandardController controller;
public Home_Model__c myCustomObject;
public HomeModelController(ApexPages.StandardController sc)
{
this.controller = sc;
myCustomObject = (Home_Model__c) sc.getRecord();
}
// Create New record and Redirect //Start Button Functionality
public PageReference New_HomeModel()
{
PageReference ret = controller.save();
Id pageid = controller.getId();
Pagereference ref = new Pagereference('/apex/HM_Entrance);
ref.setRedirect(true);
return ref;
}
}
Now Have another child object of Home Model Page. Entrance__C. Now I am having error becuase controller are diffrent :
"System.TypeException: Invalid conversion from runtime type SOBJECT:Entrance__c to SOBJECT:Home_Model__c "
I want to use the created Home_model__c record id as a parent id of child record of Entrance .
I am not able to know how to approch this. How can i pass the id from one page to another ?
public class HomeModelController {
Apexpages.StandardController controller;
public Home_Model__c myCustomObject;
public HomeModelController(ApexPages.StandardController sc)
{
this.controller = sc;
myCustomObject = (Home_Model__c) sc.getRecord();
}
// Create New record and Redirect //Start Button Functionality
public PageReference New_HomeModel()
{
PageReference ret = controller.save();
Id pageid = controller.getId();
Pagereference ref = new Pagereference('/apex/HM_Entrance);
ref.setRedirect(true);
return ref;
}
}
Now Have another child object of Home Model Page. Entrance__C. Now I am having error becuase controller are diffrent :
"System.TypeException: Invalid conversion from runtime type SOBJECT:Entrance__c to SOBJECT:Home_Model__c "
I want to use the created Home_model__c record id as a parent id of child record of Entrance .
I am not able to know how to approch this. How can i pass the id from one page to another ?
I am assuming you are trying to redirect the user to new child record page. I do not have the custom objects in my org. Let me show you an example with account and contact object,
Page: Home Controller extension:
Page: HM_Entrance:
Controller Extension:
Let me know if this helps.
All Answers
I am assuming you are trying to redirect the user to new child record page. I do not have the custom objects in my org. Let me show you an example with account and contact object,
Page: Home Controller extension:
Page: HM_Entrance:
Controller Extension:
Let me know if this helps.
Here is the senario:
Account parent record,
Home_model__C child record of account,
Entrance child record of Home_model__c,
On First page i am creating record and passing that new record value to next page . On the second page i am creating child record(Entrance__c) of the parent (Home_Model__c) Record. Now controller of both page are diffrent , so i am getting error. when i goto second page. so i am not getting id of the new created Parent Record(Home_Model__c) that i am using in second page as parent id of child record i am creating (Entrace__c).
Is it clearn now
1. If your second page is a child record of the first page then you can pull the parent recordId using a SOQL.
2. You can pass the parentId when you redirect to another page and use the get parameters to save the parentId into a variable
3. You can also use transient variables if you want to send it across.
Thanks for the reply
I am approching another method to create child record :
Here is the my code
HM_Homeaccount Page:
HomeModelController: Removing unnecessary code here HM_Entrance Page:
Before i was using diffrent standard controller : so i was having issue, now i am passing the value by taking the value by get set method and creating child record.
In Addentrance pagereference i would like to create child record using current pageid as parent id and value of
Ventilationgrilles in two custom field of entrance__c custom object.
Can you help me out here ?
Thanks