You need to sign in to do that
Don't have an account?
Save and Redirect To Next Page
I created my first controller today and I can't figure out two final steps.
I created 3 public site pages for clients to update contact information. I want to Save and go to the Next page as navigation. I verified that the controller has permission on my sites.
1. I can't get the command button to show up in the production page. http://aim.force.com/apex/MLS_Step1?ID=a19F0000001HgYX
The button is visible with the page editor.
2. I tested the button in development mode and it does forward to the next page. How do I obtain the record ID so that page two forwards to: http://aim.force.com/apex/MLS_Step2?ID=apartment.id
Thank you in advance for your help and advice.
Here is my controller:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | public class Step1Controller { Apartment__c apartment; public ApexPages.StandardController controller; public Step1Controller (ApexPages.StandardController controller) { this.controller = controller; } public PageReference save() { controller.save(); PageReference nextPage = Page.MLS_Step2; nextPage.setRedirect(true); return nextPage; } } |
I don't see you using apartmentId any where in your code,so how you the id will be used.Please change the code as follows :-
from
PageReference nextPage = Page.MLS_Step2;
to
PageReference nextPage = new PageReference('/apex/MLS_Step2?id=' +apartmentId );
All Answers
Hi,
Please try below :-
public class Step1Controller {
public Apartment__c apartment;
public Id apartmentId;
public ApexPages.StandardController controller;
public Step1Controller (ApexPages.StandardController controller) {
this.controller = controller;
apartment = (Apartment__c)controller.getRecord();
apartmentId = apartment.Id; // This is the Id of current record
}
Another way of fetching the Id is below :-
public class Step1Controller {
public Apartment__c apartment;
public Id apartmentId;
public ApexPages.StandardController controller;
public Step1Controller (ApexPages.StandardController controller) {
this.apartmentId = (Apartment__c)controller.getId(); // This is the Id of current record
}
The code saved, but it didn't execute. Per your instructions, I changed it to:
public class Step1Controller {
public Apartment__c apartment;
public Id apartmentId;
public ApexPages.StandardController controller;
public Step1Controller (ApexPages.StandardController controller) {
this.controller = controller;
apartment = (Apartment__c)controller.getRecord();
apartmentId = apartment.Id;
}
public PageReference save() {
controller.save();
PageReference nextPage = Page.MLS_Step2;
nextPage.setRedirect(true);
return nextPage;
}
}
I'm using the apex:command button in my VF Page:
<apex:pageBlock >
<apex:commandButton action="{!save}" value="Next"/>
</apex:pageBlock>
Thank you for your response, any other ideas?
I don't see you using apartmentId any where in your code,so how you the id will be used.Please change the code as follows :-
from
PageReference nextPage = Page.MLS_Step2;
to
PageReference nextPage = new PageReference('/apex/MLS_Step2?id=' +apartmentId );
That works in development but on the public page the button still isn't showing.
http://aim.force.com/apex/MLS_Step1?ID=a19F0000001HgYX
I gave the class permission in the public profile of my site. If I change the button to a standard {!quicksave} the button shows. But it won't show {!save} - I have used sites a lot...I can't think of what it might be unless I'm still missing something in the code.
Any ideas?
Thank you so much for all of your help!!
For anyone who needs to full correct code:
public class Step1Controller {
public Apartment__c apartment;
public Id apartmentId;
public ApexPages.StandardController controller;
public Step1Controller (ApexPages.StandardController controller) {
this.controller = controller;
apartment = (Apartment__c)controller.getRecord();
apartmentId = apartment.Id;
}
public PageReference save() {
controller.save();
PageReference nextPage = new PageReference('/apex/MLS_Step2?id='+apartmentId);
nextPage.setRedirect(true);
return nextPage;
}
}