Find your content:

Search form

You are here

CheckBox to Populate a Date/Time Field

 
Share

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


Attribution to: rakesh

Possible Suggestion/Solution #1

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()
{
    if(myCheckbox)
        oop.MyDatetime__c = Datetime.now();
    else
        oop.MyDatetime__c = null;

    return null;
}

Visualforce:

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


Attribution to: Sergej Utko

Possible Suggestion/Solution #2

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: http://www.eltoro.it/ArticleViewer?id=a07A000000NPRjKIAX


Attribution to: Andres Perez
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/5538

My Block Status

My Block Content