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
sairam namasairam nama 

help me in this

i've vf page where a pick list values as today,lastweek,lastmonth,next day etc and a field interview_date__c. i want to display records where interview date__c=today(or)lastweek. can any one solve this dinamically
my code is
counselor=[Select Name,Course_Fee__c,Feedback__c,Lead_Enquired_On__c,
                   Lead_Mobile_Number__c,Lead_Name__c,Status__c,Trainer_name__c,
                   Counselling_date__c from Counselling__c 
                   where Counselling_date__c=:today];
it's working 
but i want this as dinamic as
i take a string date and i want to give it as Counselling_date__c=:date....
help me in this case
thanks in advance
Sohan Raj GuptaSohan Raj Gupta
Hi Sairam,

In this case you need to write SOQL query in String and for excute query use List<sObject> sobjList = Database.query(string);

I created sample code for you. You can use this for your reference:
 
<apex:page controller="VechileDate">
  <apex:form>
      <apex:pageBlock>
          <apex:pageBlockSection>
          Date: <apex:selectList value="{!dateVal}" multiselect="false" size="1">
              <apex:selectOption itemLabel="Today" itemValue="Today"></apex:selectOption>
              <apex:selectOption itemLabel="LAST WEEK" itemValue="LAST_WEEK"></apex:selectOption>
              <apex:selectOption itemLabel="LAST MONTH" itemValue="LAST_MONTH"></apex:selectOption>
              <apex:selectOption itemLabel="Next Day" itemValue="TOMORROW"></apex:selectOption>
          </apex:selectList>
          
          <apex:commandButton value="Search" action="{!Search}"/>
          </apex:pageBlockSection>
      </apex:pageBlock>
  </apex:form>
</apex:page>
 
public class VechileDate{
    
    public String dateVal {get;set;}
    
    public VechileDate(){
        
    }
    
    public void Search(){
        List<Vehicle__c> vehicles = new List<Vehicle__c>();
        String qyr = 'select ID from Vehicle__c where Close_Date__c =' + dateVal;
        vehicles = Database.query(qyr);
    }

}

Hope this will help you.

Please let me know if it helped or you need any more assistance. Please mark this is as the solution if it solved your purpose.

Thanks,
Sohan Raj Gupta