+ Start a Discussion
jls_74_txjls_74_tx 

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;
}
}

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Vinit_KumarVinit_Kumar

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

Vinit_KumarVinit_Kumar

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

}

jls_74_txjls_74_tx

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;
}
}

 

  1. The button still doesn't show on the public site page:  http://aim.force.com/apex/MLS_Step1?ID=a19F0000001HgYX
  2. When I click the button in development mode, it forwards to: http://aim.force.com/apex/MLS_Step2 - no ID number is attached.

 

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?

 

Vinit_KumarVinit_Kumar

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 );

This was selected as the best answer
jls_74_txjls_74_tx

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;
}
}