You need to sign in to do that
Don't have an account?
tsalb
PageRef redirect to ID not working?
I have a really simple extension to override save behavior - but I can't get it to redirect to the object's lookup relationship record?
Hardcoding the Account__c (lookup ID) seems to work fine. Commenting out the pagereference redirects, and just updating sub works fine too. I'm still pretty new to Apex/Visualforce so what am I missing here?
public class SubmissionExtension { private final Submissions__c sub; //Controller public SubmissionExtension(ApexPages.StandardController sCon) { this.sub = (Submissions__c)sCon.getRecord(); } //Overrides default save method - no redirects (which default save does) public PageReference save() { update sub; PageReference redirect = new PageReference('/' + sub.Account__c); //PageReference redirect = new PageReference('/001S000000WPXVR'); return redirect; } }
<apex:page standardController="Submissions__c" extensions="SubmissionExtension" showHeader="false" sidebar="false"> <apex:form > <table border="1" cellpadding="5" cellspacing="0" frame="border" style="width:100%"> <tr> <td width="98%" height="60px"> 1. TEST<br/> <apex:inputTextArea style="width:100%; height:40px;" value="{!Submissions__c.q1e__c}" id="q1e"/></td> <td colspan="2"> <apex:selectRadio value="{!Submissions__c.q1__c}" layout="lineDirection"> <apex:selectoption itemValue="true"></apex:selectoption> <apex:selectoption itemValue="false"></apex:selectoption> </apex:selectradio></td> </tr> </tbody> </table> <apex:commandButton value="Save Accord Form" action="{!save}" id="thebutton"/> </apex:form> </apex:page>
Bascially you need to query for the ID after the below record to get the redirect working.
ID recordid=(Submission__c)sCon.getRecord().id;
sub=[select id,account__c from Submision__c where id=:recordid];
All Answers
The standard controller doesn't populate the entire record - rather it looks at which fields you are using in the page and populates those. Thus I suspect the account__c field is empty.
Try adding the following to your page - this will populate the field without displaying it:
Bascially you need to query for the ID after the below record to get the redirect working.
ID recordid=(Submission__c)sCon.getRecord().id;
sub=[select id,account__c from Submision__c where id=:recordid];
Thanks all, this makes a lot of sense - Both of your examples helped immensely. Much Apprecaited guys.