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

how do recreate 'apex/pageName?=id.... ' when the record has not been created yet?

Hi everyone,

I have been a SF admin for a while now and I'm staring to dive into some customization.

In theory, what I'm trying to do is simple. I have a custom object, which has a lookup relationship with the Opportunity object.

Here's the user journey:

1) New record is created via related list on opportunity (has to be this way)

2) Edit page loads with opportunity name lookup field pre populated

3) User clicks save

4) All lookup and formula fields get to work and the record is completed

This is all working fine.

However, I needed to build a visualforce page for the custom object records (detail page).

How do I replace the custom object record page layout with my visualforce page?

When I test the page by adding the id to the URL (?=id.....) the page works great. I can't work out how to do this automatically. 

I have tried creating a new Save button, but the page loads blank.

I have also been reading up on extending the VF page, and then overriding the save button with a new Save method. When I do this, I don't know how to format the pageReference URL because the record id has not been created yet.

Can anyone provide some guidance please? Im happy to provide code, although the VF is quite long.


I think parameter should refer to parent (oppportunity) record id and this record exists already.

Don't really understand what you are currently trying to pass in this parameter.

You don't need id parameter of record being inserted.

Set the view button to visualforce page that you created on the custom object. That should resolve your requirement. The below article might help

Ok thanks Patlatus. I'm just reading through the pageReference info which goes with what you are saying. Could I use something like below in a controller extension?

Save method {
insert new record
load new visualforce page



...or is there an easier way? I'm quite surpised its so easy to build an entire app without code, but adding a VF page requires apex methods. Seems odd to me. 


Actually I don't understand why do you want to implement custom page.

You can implement this any way you like (including custom page and using pageReference in controller), but it seems to me that it would be much easier to use standard button. Salesforce has implemented functionality for that what you need. All you have to do is to enable it on page layout.


Ah man, I've spent 1.5 days trying to figure out how to override the Save button. Turns out, it was the View button I needed to override. 

Guys thanks so much for your help here. I really appreciate it, expecially as I'm not the best at describing what I'm trying to do sometimes. 
Have a nice weekend. I can finally sleep now that I know how to do this!

Thanks again :)