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
SS KarthickSS Karthick 

Date Literal as cusom picklist in visualforce page

Hi folks,
       Can anyone tell me how to use the Date Literal in apex?
My use case is I want to use Date literal as a custom picklsit.
I want to create custom picklist as follows
User-added image


Please someone tell me how can I implement,


Thanks in advance,
Karthick
pconpcon
To do this you'll have to get the picklist value inside of your controller, then using the Database.query call make a dynamic query that incorporates the literal into it. 
 
String literal = 'THIS_YEAR';
String query = 'select Id from Case where CreatedDate = ' + literal;

List<Case> cases = (List<Case>)(Database.query(query));
System.debug(cases);

 
Sudeep DubeSudeep Dube
Yes, 1  . first You can create the custom pick list of date literals using 'select option'  
               I) if u want to hard code these values then in Vf controller put the values
               II) if you want to dyanamic literal values in picklist then use custom setting for the Date literal where you(admin) can put the values of date literrals then these values have to access in Vf controller and using these value (stored in custom setting) create the custom picklist 

       2. now use select list and select option on vf page and use the String variable with get set properties in select list
      3. use action suppert in select list tag then call on click the action of vf controller and create the dynamic quesry to fetch the vaues of relative select list string variable


I hope the dteps will help you 

Regards
Sudeep Dubey...