You need to sign in to do that
Don't have an account?
Richard Houston 20
Visualforce custom save returns pagereference null
Hi,
I have a custom visualforce page with a working save and insert button for a custom child object of opportunities.
However, I'm running into an issue with the save and redirect when going back in to view/edit the record. I've overriden the custom object's view button to direct to a copy of the existing visualforce page. This one only has a button to update the record instead of inserting a new one. Looking at the debug logs the parent opportunity ID never seems to get passed through and then the page reference returns null.
How do I go about getting that ID so I can return users to the page they came from?
Thanks!
Controller Extension:
Visualforce Page
I have a custom visualforce page with a working save and insert button for a custom child object of opportunities.
However, I'm running into an issue with the save and redirect when going back in to view/edit the record. I've overriden the custom object's view button to direct to a copy of the existing visualforce page. This one only has a button to update the record instead of inserting a new one. Looking at the debug logs the parent opportunity ID never seems to get passed through and then the page reference returns null.
How do I go about getting that ID so I can return users to the page they came from?
Thanks!
Controller Extension:
public with sharing class SurveyParentIDExt{ public Pursuit_Survey__c OpportunityParent{get;set;} public SurveyParentIDExt(ApexPages.StandardController controller){ OpportunityParent=(Pursuit_Survey__c)controller.getRecord(); system.debug(OpportunityParent); String parentID = System.currentPagereference().getParameters().get('parentid'); OpportunityParent.Opportunity__c=parentid; system.debug(parentid); } public PageReference doSaveWithRedirect(){ Upsert OpportunityParent; system.debug(opportunityparent); PageReference ref = new PageReference('/' + System.currentPagereference().getParameters().get('parentid')); system.debug(ref); ref.setRedirect(true); return ref; } public PageReference saveandUpdate(){ Update OpportunityParent; system.debug(OpportunityParent); PageReference ref = new PageReference('/' + System.currentPagereference().getParameters().get('parentid')); system.debug(ref); ref.setRedirect(true); return ref; } }
Visualforce Page
<apex:page standardController="Pursuit_Survey__c" extensions="SurveyParentIDExt"> <apex:form > .. .. .. [Skipping the body to keep this shorter] <apex:commandButton value="Update Responses" action="{!saveandUpdate}" /> </apex:form> </apex:page>
You may want to try storing the parentid value in the constructor. Perhaps it's being cleared before the saveandUpdate method can grab it.
Try this:
Hope that helps,
Clint
Thanks for the quick reply. I'm passing parentid through a custom button on the opportunity.
/apex/Pursuit_Survey?parentid={!Opportunity.Id}
I'm not sure how I would pass that through on a related list view override though.
Thanks again for the help!
/apex/Pursuit_Survey?parentid={!Opportunity.Id}&id={!Pursuit_Survey__c.id}
You need to keep your custom Button on the detail page of Opportunity instead of related list, you will get opportunity Id after that in your
Pursuit_Survey Vf page.
Please let me know if need more inputs.
Thanks,
Vishal