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
Varun TejaVarun Teja 

If I select Picklist value date fileds should be populated automatically

Can you please help on below criteria.

1) A picklist showing values 2011, 2012 and 2013
2) 2 Date fields (From Date and To Date)
3) When user picks the value in 1st picklist, From and To Date should automatically populate.
Ex: If I select 2011, From Date should be 01/01/2011 and End ddate should be 12/31/2011 automatically populate
If I select 2012, From Date should be 01/01/2012 and End ddate should be 12/31/2012 automatically populate

I have picklist as Year__c

Below formula has been given in From Date filed.

CASE(Year__c, 
2011 , DATE(2011,01,01) , 
2012, DATE(2012,01,01),
DATE(2013,01,01)


Getting error as "Error: Field Year__c may not be used in this type of formula"

Thanks In Advance
Best Answer chosen by Varun Teja
Somya SrivastavaSomya Srivastava
Hi Varun,

Use this:

CASE(Year__c, 
'2011' , DATE(2011,01,01) , 
'2012', DATE(2012,01,01),
DATE(2013,01,01)


Thanks
Somya


 

All Answers

Somya SrivastavaSomya Srivastava
Hi Varun,

Use this:

CASE(Year__c, 
'2011' , DATE(2011,01,01) , 
'2012', DATE(2012,01,01),
DATE(2013,01,01)


Thanks
Somya


 
This was selected as the best answer
Varun TejaVarun Teja
Hi Sowmya,

Getting errorUser-added image
kamala swarnalathakamala swarnalatha
Hi,

You try this one

From date field

OR(
ISPICKVAL('2011',DATE(2011,01,01)), 
ISPICKVAL('2012', DATE(2012,01,01)),
​ISPICKVAL('2013',DATE(2013,01,01))
)

To date field

OR(
ISPICKVAL('2011',DATE(2011,12,31)), 
ISPICKVAL('2012', DATE(2012,12,31)),
​ISPICKVAL('2013',DATE(2013,12,31))
)
Hope this helps!

Please mark it as solved if my reply was helpful. It will make it available for other as the proper solution.

Thanks,
K.Kamala
Sweet Potato Tec.
 
Varun TejaVarun Teja
Hi Sowmya,

One more help from you.

How to display from date and to date in VF page..means which apex tag need to use..        

<apex:inputField value="{! acount.Year__c }" id="year"/>        
<apex:outputText  value="{! acount.From_Date__c }" rendered="{!year}"/>
<apex:outputText value="{! acount.To_Date__c }" rendered="{!year}"/>

Not working
Somya SrivastavaSomya Srivastava
Hi,

Use apex:outputtext tag in your visualforce page.
Somya SrivastavaSomya Srivastava
Hi,

Please share your complete VF code.
Varun TejaVarun Teja
Hi,
Please find the below code

<apex:page standardController="Account" extensions="AccountRevenueController" >
    <apex:form >
        <apex:pageBlock rendered="true">

            <apex:pageBlockSection columns="1">
 
                <apex:inputField value="{! acount.Year__c }" id="year"/>
                <apex:outPutField  value="{! acount.From_Date__c }" rendered="{!year}"/>
                <apex:outPutField value="{! acount.To_Date__c }" rendered="{!year}"/>

             </apex:pageBlockSection> 
            <apex:pageBlockButtons location="bottom">
                <apex:commandButton value="Submit" />
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>
Somya SrivastavaSomya Srivastava
Hi Varun,

Firstly, please check your spelling for account:
<apex:outPutField  value="{! acount.From_Date__c }" rendered="{!year}"/>

Secondly, in

rendered="{!year}

what is 'year' ? 
Varun TejaVarun Teja
Hi Sowmya,

First acount is an object reference of Account
Second one ,just i declared id=year for rendering.

Apex class:
public class AccountRevenueController {
    
    public Account acount{get; set;}
    public String fromdate {get; set;}

    
    public AccountRevenueController(ApexPages.standardController controller){  
        acount = new Account();
    }
}
 
Varun TejaVarun Teja
Hi Sowmya,

Please help me on this