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
angusgrantangusgrant 

Default values not displaying on New Entry

Hi I just re-created a custom object entry edit/new page using vf and for some reason it no longer displays the default values for those fields where I have set a default value.

 

For example the field SBS_Event__c.venue_postcode__c is a text field and Should have a default value set. Also all the following should have default values and are checkboxes and should default to checked <apex:inputField value="{!SBS_Event__c.Available_Oxford_University__c}" />

<apex:inputField value="{!SBS_Event__c.Available_Business__c}" /> <apex:inputField value="{!SBS_Event__c.Available_Other_Charity__c}" /> <apex:inputField value="{!SBS_Event__c.Available_Other_Charity__c}" /> <apex:inputField value="{!SBS_Event__c.Available_Public_Sector_Applicants__c}" /> <apex:inputField value="{!SBS_Event__c.Other_Induvidual_No_Organisation__c}" />

 

<apex:page standardController="SBS_Event__c" title="SBS Events Layout Page" showHeader="true" sidebar="true"> <apex:sectionHeader title="{!$ObjectType.SBS_Event__c.label}" subtitle="{!SBS_Event__c.name}"/> <apex:form > <apex:pageBlock title="SBS Event Edit"> <apex:pageBlockButtons > <apex:commandButton value="Save" action="{!save}"/> </apex:pageBlockButtons> <apex:pageBlockSection title="Information" columns="1"> <apex:InputField style="width:350px" value="{!SBS_Event__c.Name}" required="true" /> <apex:inputField value="{!SBS_Event__c.Event_Brief_Description__c}" style="width:450px" required="true"/> <apex:pageBlockSectionItem > <apex:outputLabel for="eventdetails">Event Description (for web)</apex:outputLabel> <apex:inputTextarea value="{!SBS_Event__c.Full_Event_Details__c}" id="theTextarea" richText="true" id="eventdetails" required="true" style="border: 3px solid red;" /> </apex:pageBlockSectionItem> <apex:inputField value="{!SBS_Event__c.Event_Start_Date__c}" required="true" /> <apex:inputField value="{!SBS_Event__c.Event_Finish_date__c}" required="true"/> <apex:inputField value="{!SBS_Event__c.Contact_Information__c}" required="true" style="width:350px"/> <apex:inputField value="{!SBS_Event__c.Alternative_Contact_Information__c}" style="width:350px" /> <apex:inputField value="{!SBS_Event__c.Maximum_Capacity__c}"/> <apex:inputField value="{!SBS_Event__c.Display_on_website__c}"/> </apex:pageBlockSection> <apex:pageBlockSection title="Location" columns="2"> <apex:inputField value="{!SBS_Event__c.Venue__c}" required="true" /> <apex:inputField value="{!SBS_Event__c.venue_postcode__c}" required="true" /> </apex:pageBlockSection> <apex:pageBlockSection title="Applicant type availability to Apply" columns="2"> <apex:inputField value="{!SBS_Event__c.Available_Oxford_University__c}" /> <apex:inputField value="{!SBS_Event__c.Available_Business__c}" /> <apex:inputField value="{!SBS_Event__c.Available_Other_Charity__c}" /> <apex:inputField value="{!SBS_Event__c.Available_Other_Charity__c}" /> <apex:inputField value="{!SBS_Event__c.Available_Public_Sector_Applicants__c}" /> <apex:inputField value="{!SBS_Event__c.Other_Induvidual_No_Organisation__c}" /> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>

 

 

 

Message Edited by angusgrant on 08-19-2009 02:02 AM
Rajesh ShahRajesh Shah

The default values dont come in my case too. I think it is one of those things that doesn't works with inputField. Here are some of the things that don't work with inputField

 

1. Default value for a field.

2. Default value of a Picklist.

3. Dependent picklist.

sfdcfoxsfdcfox

Default values do not apply in Visualforce from the organization's metadata. You can, however, programmatically access fields' default values using Schema.SobjectType.ObjectName.fields.getmap(); this returns a map full of tokens. You can then go through the tokens, calling getDescribe().getDefaultValue() on each token. Please refer to the documentation for more information.

Rajesh ShahRajesh Shah

Ya that is one way to fetch the default value of a field dynamically.

But with a page having many fields, I worry that I would exceed the getDescribe limits. Also, it is ok to do it for fields which I know have a default value. But later on, if somebody goes and assigns a default value to another field, I will again have to add that part in the code.

Please correct me if I am wrong