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
affableaffable 

help me

i have two custom obects dep2__c and emp2__c , i have related dep2__c object to emp2__c through lookup.

 i have to select start date and endate  and department number then  ihave fetch according to selected values. but am unable to bind date in visual page .and fetch corresponding records.

help me to write apex code for above issue .

 

public class Dcontroller
{
Date sate;
Date startdate;
Date enddate;

List<dept2__c> deptList;// departmentList
List<emp2__c> employeesList;//employeeList
String departmentNumber='10';
public Dcontroller()
{
 employeesList=[select name,Id,doj__c from emp2__c];
 deptList =[select Id,name,dept2No__c,Location__c from dept2__c];
 startdate=[select doj__c from emp2__c].doj__c;
 enddate=[select doj__c from emp2__c].doj__c;
 }
 public List<emp2__c> getdate()
 {
  List<emp2__c> sate;
  sate=[select doj__c,name,Address__c from emp2__c];
  return sate;
  }
public List<SelectOption> getItems()
{
List<selectOption> options = new List<selectOption>();
 for(dept2__c dept : deptList)
 {
  String departmentNumber1 =String.valueOf(dept.dept2No__c);
  options.add(new selectOption(departmentNumber1,dept.name));
 }
 return options;
}
 public Date getSDate()
 {
  return startdate;
 }
 public void setSDate(Date sdate)
 {
  startdate =[select doj__c from emp2__c where doj__c=:sdate].doj__c;
  }
   public Date getEDate()
 {
  return enddate;
 }
 public void setEDate(Date edate)
 {
  this.enddate=[select doj__c from emp2__c where doj__c =:edate].doj__c;
  }
  public String getdepartmentNumber()
 {
 return departmentNumber;
 }
 public void setdepartmentNumber(String departmentNumber)
 {
 this.departmentNumber=departmentNumber;
 }
  public List<emp2__c> getemployees()
 {
 
  Id id=[select Id from dept2__c where dept2No__c=:departmentNumber].ID;
  employeesList=[select name,doj__c,employeeId__c,salary__c,Address__c from emp2__c where dept2No__c=:id and (doj__c=:startdate or doj__c=:enddate)];
  return employeesList;
 }
 public pageReference go()
 {
 return null;
 }
 }