You need to sign in to do that
Don't have an account?
Open VF Page in 'Add' mode
I want to be able to create new record with some fields pre-populated with default value and display to user ready for save. The new record window I want to invoke from a class. For my similar post earlier, Ron Hess has suggested me to use visualforce page with custom controller and extension to read parameter and assign them to new case. Below is what I tried.
Test_Object__c
Name
Log_Date__c
Score__c
TestObjectPage.page
<apex:page standardController=" Test_Object__c" extensions="TestObjectExtension"> <apex:pageBlock> Test Object Name = {! Test_Object__c.Name} PrmName = {!prmName} </apex:pageBlock> <apex:detail/> </apex:page>
This displays my object’s detail page in detail window.
TestObjectExtension.cls
public class TestObjectExtension{ private final Test_Object__c t; String name; public TestObjectExtension(ApexPages.StandardController stdController){ this.t = (Test_Object__c)stdController.getRecord(); String prmName = System.CurrentPageReference().getParameters().get('name'); this.name = prmName; t.Name = prmName; System.debug('abcd'); System.debug(prmName); } public String getPrmName(){ return this.name; } }
To use this page in ‘View’ mode, I overrode ‘View’ button with my VF page. When I click any record in this object, my VF page is displayed correctly. It also executes my class.
But as per my requirement, I overrode ‘New’ button with my VF page so that when a new record is being created, my VF page is displayed so that I could pre-populate some of the fields.
When I click on the ‘New’ button, it returns error as ‘Unable to Access Page’.
Do I need to override the button at all? How could I call my VF page to open in ‘add’ mode and populate some of the fields?
Please help
As for populating the fields, the solution you have will work as long as a name parameter is passed in. So I guess the best way to do this (provided that the value has to be passed in by a parameter and is not something static you can put in your controller), you will have to override the tab page and provide your own "new" action, that basically returns the edit page (for accounts it is 001/e) with a name parameter.