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
JesseRCJesseRC 

PageReference to new lead page with prepopulated fields

We have an intermediary new lead page that takes basic fields (name, phone, email, company) and searchs showing possible duplicates. When one is not found then the user can choose to create his new lead. The lead is created with all the data the rep has already filled out, inserted and then shown to the user via a a pagereference. 

 

Is there a way to not "insert" the lead before showing it? I would like for agent's to have a chance to change some other field data before the initial insert trigger is fired. I just want to open the lead to its edit page 

Best Answer chosen by Admin (Salesforce Developers) 
dwwrightdwwright

From my experience, what you're suggesting is not possible because in order to pass a PageReference that displays a record, you have to use the Id [e.g. PageReference ref = new PageReference('/apex/mypage?id=' + Lead.Id)]. Obviously, needing the Id means you need to do an insert...

 

If you stay within the instance of your VisualForce page, however, and use a custom controller (or an extension that references the standardController for Lead) You can do everything from one page. You would have different sections of the page based on what stage of the process the user is in, using the renderas attribute to control what is displaying. Your action methods can then just return null and your instance of Lead will maintain the information without having to be inserted into the database.

 

Here's what it might look like functionally:

 

1. User sees page block with initial input fields. They put in the information and click submit.

 

2. Your controller executes an action method (behind the submit button) and searches for a duplicate.

 

3. a. A duplicate is found, so your page refreshes (return null in the controller method) and now shows a "Duplicate found" page block.

 

3.b. No duplicate is found, so the page refreshes and shows the standard lead edit page. From here the user can finish inputing data and submit the lead, inserting it into the database.

 

The downside to this is that you would have to build the "edit page" from scratch using Visualforce, so if you needed to make layout changes later, you would have to do it through visualforce and not the WYSIWYG editor.

 

Hope this helps.

All Answers

dwwrightdwwright

From my experience, what you're suggesting is not possible because in order to pass a PageReference that displays a record, you have to use the Id [e.g. PageReference ref = new PageReference('/apex/mypage?id=' + Lead.Id)]. Obviously, needing the Id means you need to do an insert...

 

If you stay within the instance of your VisualForce page, however, and use a custom controller (or an extension that references the standardController for Lead) You can do everything from one page. You would have different sections of the page based on what stage of the process the user is in, using the renderas attribute to control what is displaying. Your action methods can then just return null and your instance of Lead will maintain the information without having to be inserted into the database.

 

Here's what it might look like functionally:

 

1. User sees page block with initial input fields. They put in the information and click submit.

 

2. Your controller executes an action method (behind the submit button) and searches for a duplicate.

 

3. a. A duplicate is found, so your page refreshes (return null in the controller method) and now shows a "Duplicate found" page block.

 

3.b. No duplicate is found, so the page refreshes and shows the standard lead edit page. From here the user can finish inputing data and submit the lead, inserting it into the database.

 

The downside to this is that you would have to build the "edit page" from scratch using Visualforce, so if you needed to make layout changes later, you would have to do it through visualforce and not the WYSIWYG editor.

 

Hope this helps.

This was selected as the best answer
JesseRCJesseRC

That does seem like the most complete way to accomplish this. Thanks Dwwright.