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
Ankit GuptaAnkit Gupta 

Default values not displayed for inputfield

Hi,

I have a scenario whenever a person goes to the Home Tab,he is taken to a Disclaimer Page and whenever he/she accepts the terms,a new section is rendered of the same VF page which has a standard controller and apex tags like inputfield which have a default value set at the field level.But I am not able to get the default values as soon as I hit Accept Terms and conditions button.

But if I have two different VF Pages,this works very fine and I am able to get the default values.
Any inputs are highly appreciated.

Regards,
Ankit Gupta
SFDC Developer



Ashish_SFDCAshish_SFDC
Hi Ankit, 


In your constructor call the method with 0 attributes to show defaults. 


Regards,
Ashish
Ankit GuptaAnkit Gupta
Hi Ashish,

I did try this but still it doesnot turn out.The default values are not displayed. The only way I see it assigning default values again in the constructor the field values.

Ashish_SFDCAshish_SFDC
Hi Ankit,


To provide defaults via Visualforce, you need an "extension". In the extension's constructor, you would provide the default value to use.

Ex,

<apex:page standardController="Task" extensions="TaskExtension">
  <!-- your code here -->
</apex:page>

public class TaskExtension {
  public TaskExtension(ApexPages.StandardController controller) {
    Task t = (Task)controller.getRecord();
    t.Subject = 'Default Subject';
  }
  public static void testMethod test() {
    Task t = new Task();
    ApexPages.StandardController controller = new ApexPages.StandardController(t);
    TaskExtension extension = new TaskExtension(controller);
    System.assertEquals(t.Subject,'Default Subject');
  }
}
Normally, it's a ton more efficient to just name a default value on the actual field (setup > customize/create > object > fields) rather than go through this dance, but it's a good starting point.


See more information on the below thread,

https://developer.salesforce.com/forums/ForumsMain?id=906F0000000972lIAA

Also see below another similar thread,

https://developer.salesforce.com/forums/ForumsMain?id=906F000000098FeIAI


Regards,

Ashish