function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Glenn at MvistaGlenn at Mvista 

PageReference using Apex - hopefully a simple question

I create a Visual force page to call an apex controller to create a new object.  Basically creating a Contract from the Account via a button so I can control some of the default values in the Contract, based on the Account.

 

However, there is one piece, the Contact, that I cannot predetermine as there are many contacts on an account typically.  So, what I wanted to do was have the PageReference open in Edit mode.  I was able to do that easily.  So here are the page references and results

 

        return new PageReference('/'+c.Id);

This lands on the new Contract, but is not open for editing.

 

        return new PageReference('/'+c.Id+'/e');
This lands on the new Contract in Edit Mode.  Which is correct, because I then made the Contact Signed By field required and the only editable field on the page - so the requestor can complete it.

 

However, after entering the Contact and saving the record again, the user is brought to the Home Page, not the Contract record.  Is there anyway I can control where the save takes them?  A second PageReference maybe?

Best Answer chosen by Admin (Salesforce Developers) 
IbigfootIbigfoot
try adding the url parameter

retURL= {id.of.where.u.want.to.go}

not sure if this works , is how i would try it if setting the url in a custom button or something

All Answers

IbigfootIbigfoot
try adding the url parameter

retURL= {id.of.where.u.want.to.go}

not sure if this works , is how i would try it if setting the url in a custom button or something
This was selected as the best answer
Glenn at MvistaGlenn at Mvista

Thank you so much.  Simple as I had hoped.  For the official record, here is the new pagereference in its working entirety

 

return new PageReference('/'+c.Id+'/e?retURL=/'+c.Id);