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
patskepatske 

Assign a default value to a field

Hi all,

I'm having some trouble passing default values into <apex:inputFields> is it possible? For instance if I want to set

<apex:inputHidden value="{c.Sales_Prospect__c}" /> to a certain value can I do it?

Basically I'm looking for a similar action to HTML where I can have something like the following

<input type="hidden" name="sales_prospect__c" value="David G">

I've looked through the attributes of <apex:inputHidden> and <apex:inputField> and noticed there are none for default value.

any help would be much appreciated.

basically my problem is that in my code {c.Sales_Prospect__c} is a lookup field. when I submit the form I have created I know what value I want to put in that field but I just can't seem to do it, it's always blank and creates an unrelated record.

P.S I am new to visual force here

Thanks,

Patrick


Message Edited by patske on 05-30-2008 12:05 AM

Message Edited by patske on 05-30-2008 12:07 AM
ESES
May be in your controller/extension you can initialize the field to whatever you want.
EricReichertEricReichert
How can you do this through the custom controller or extension?

I've been trying to figure out a way to do it for 3 days now.
patskepatske
The way I did it Eric was in my Controller/Extension I returned my object with a prepopulated field.

for e.g

Code:
Sales_Prospect__c salesprospect = new Sales_Prospect__c(Account__c = aId, Salesperson__c = UserInfo.getUserId(), Amount__c = 0.00, Close_Date__c = date.today(), Stage__c = 'Prospecting');

public Sales_Prospect__c getSP() {
   return salesprospect;
}

 So when I'm creating a new record I add it to the values of the field. The same can be done when adding objects to a list.

Hope this helps

EricReichertEricReichert
Another poster gave me way to do it in a different thread  .  Now I have 2 ways of getting the job done.

Thanks