Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Hi I created a Visual force page for opportunities and displayed check box what I am looking after if checkbox == true then a date/Time field in opportunity need to populate with today's date.

Can anybody help me out with some sample piece of code please

share|improve this question… The above link can help you get started ! – Mohith Shrivastava Dec 18 '12 at 11:38
up vote 2 down vote accepted

Apex method:

public Opportunity oop { get; set; }
public Boolean myCheckbox { get; set; }

// Constructor
public YourClass()
    // Defaulf value of the checkbox
    myCheckbox = false;

public PageReference setDatetime()
        oop.MyDatetime__c =;
        oop.MyDatetime__c = null;

    return null;


<apex:inputCheckbox value="{!myCheckbox}">
    <apex:actionSupport event="onchange" reRender="none" action="{!setDatetime}"/>

share|improve this answer
Hi mastOr this thanks for the reply, im not displaying any input fields in visual force page only displaying the records. if check box is checked and saved then date/time field should populate in UI page and record need to be save – rakesh Dec 18 '12 at 13:02
HI, just updated my code. If checkbox is clicked - the date field populated with current date/time. I think this is what you mean an need? – Sergey Utko Dec 18 '12 at 13:44
hi mastOr im sorry abt i didnt clearly mentioned the question im really sry abt that, i displayed the opp records on vf page with <apex:inputCheck box/> but not the custom field when the checkbox is true then the date/time field in opp should populate with today date( – rakesh Dec 18 '12 at 13:52
Just updated my example for use with a normal checkbox. Hope this help. – Sergey Utko Dec 18 '12 at 14:04

What you are trying to do is quite common, I have few articles about this topic. I think the closest to what you are looking for is:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.