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
ethanoneethanone 

Pre Populating Required Field

There are a few required fields in both standard objects and custom objects that I would like to pre-populate when they are created so that the user doesn't feel compelled to fill them in (since they are required).  What I'm talking about is having the data in the field box before the user clicks "save".  I know I can do this after the user clicks "save" (and that is what I'm already doing), but I want the fields filled as soon as the user sees the blank form.

 

Alternatively, is there a way I can make an exception to hide required fields that a trigger will populate before insert?

OnkiOnki

Hi

 

 

use the following steps to prepoulate the filds:

 

1. override the new/edit button with visulaforce page

2. view source of the  edit page of records for which you want to prepoluate the fields

3. get Id (HTML control ID) from viewd source code.

4. assign the value for this control from Querystring in visualforce page.

5. redirect standard EDIT page from Visualforce.

 

Note add your Object as controller in visualforce

 

Thanks

Onkar

 

 

 

 

 

 

 

PratibhPratibh

Hi,

 

You can set default values for field when field is created or you can also edit the field properties for existing  to achieve the same(for some type of fields like text field).

 

By doing this values will be prepopulated in the fields whenever new record is created.

 

wesnoltewesnolte

Hey

 

Yes you can do both of these things.

 

First of all let's save you have a required field on your form:

 

<apex:page controller="myController">

 ...

<apex:inputField value="{!myValue}" />

... 

 

You can do the following in your apex controller:

 

public class myController{ 

 

public String myValue{get;set;} // will get and set the value 

 

public myController(){

  myValue = 'Hello There'; // this value will be displayed in the field when the page loads

 

Your second question is a bit more complex depending on your exact case. You could try this although I'm not sure you'll get the results you'd like:

 

Don't put the field onto the form at all.

Create a before insert trigger for you object and assign a value within that trigger.

 

You'll have to experiment with the second solution but that should get you started.

 

Cheers,

Wes 

EchoEchoEchoEcho

Hi All,

 

I'm trying to do this, but every time I try to redirect to the standard EDIT page from my Visualforce override page, I get an infinite loop of redirects from the standard EDIT to the VF to the standard EDIT to the VF. Is there any way to get around this?

 

 



1. override the new/edit button with visulaforce page

2. view source of the  edit page of records for which you want to prepoluate the fields

3. get Id (HTML control ID) from viewd source code.

4. assign the value for this control from Querystring in visualforce page.

5. redirect standard EDIT page from Visualforce.

 

 


 

 Thanks,
Tom

 

WesNolte__cWesNolte__c

Hey

 

You can set a parameter to override the redirect the second time. This article might help, specifically you're looking at the nooveride part:

 

http://salesforcesource.blogspot.com/2008/12/urlfor-function-finally-explained.html

 

Or if you're building the URL manually you need to set the nooverride URL parameter to 1.

 

Wes