+ Start a Discussion
Jon KeenerJon Keener 

Reproducing Standard "New" object functionality in Visualforce

I've been reading through the documentation and the board for a means of creating a standard input page in VisualForce that populated the form based on the page layout associated with the current user.  It at first seemed that this would be easy, but I haven't found a way to do it.  I at first figured that there might be an attribute on the Detail component to control the mode, so that it would show an input screen for a new record vs. the standard detail screen, based on the page layout of the user.  Unfortunately it doesn't seem to have that capability.  Below is an explaination of what I'm trying to do, so it'll make a little more sense:
I've got a Sample Request custom object that has 3 lookup fields on it.  The lookup fields are Account, Contact, and Opportunity.  Both the Account and Contact are required when creating a Sample Request.  The Opportunity is optional.  What I want to do, is add a button on the Sample Request object that will create an Opportunity record and automatically associate the Sample Request with the brand new opportunity.
As to the details of what I want to do, they are:
1.  Based on the Account the Sample Request is associated with, I can auto determine what RecordType the Opportunity should be, so the user shouldn't have to select RecordType.
2.  I want to present the user with the Input Screen based on the Page Layout.  (We have total of 12 RecordTypes and 14 Page Layouts, with differing required fields/picklists based on the combination, so I want to avoid trying to create a custom form)
3.  After the Opportunity is Saved, I need to update the Sample Request with the new Opportunities Id.
Another option I could try to implement is to override the Opportunity "Save" button, and have it look for a parameter on the URL of the sampleRequestId.  I haven't tried overriding a "Save" button in this way before, so I'm not sure if this is a good approach or not for this.  I was hoping to be able to make a simple VF page to perform the above so as to limit the exposure of custom logic to only Opportunity Saves that were related to Sample Requests.
Any ideas would be great!  Thanks!
Jon Keener
The input side of apex:detail has not been created. We are not sure whenthat will make it on the roadmap and what it might look like - we are considering the future convergence of page layouts and visualforce pages when making investments like this one.

In the meantime, one suggestion I have for you is to make the opportunity create form (or portion of the form) as simple as it can be and then give the user the option to add additional information after saving the sample request by directly navigating them to edit form for the opportunity - the standard edit page.

This might make sense because if the user went to create the sample object first they may not have all the necessary information to create a complete opportunity anyway - but you would know your users best.

So in this flow your sample form would have an inputField for the opportunity with a way to choose to create a new opportunity if one doesn't exist. If the user indicates they want to create a new opportunity in conjunction with this sample, then you give them inputs for the basic opportunity fields common to all your types and on save you can selectively move them to the standard opportunity edit form or give them the option with a specific save & redirect button.

The other options seem fairly heavily manual given the components and capabilities we have today.


Message Edited by mtbclimber on 02-17-2008 09:25 AM

Message Edited by mtbclimber on 02-17-2008 09:25 AM