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
lovetolearnlovetolearn 

Need help with Apex class

Hi, 

 

I am trying to write a Apex class to find all the SDO days associated with a user based on the user input on the VF page. I didn't get any errors from my code, but not sure why it is not working. Here is my code: 

 

public with sharing class exDeleteSDO {

    public exDeleteSDO(ApexPages.StandardController controller) {
    }
    
    public String sdoType{get; set;}
    public Date sdoFrom {get; set;}
    public Date sdoTo {get; set;}
    public string empName{get; set;}
    List<Schedule_Days_Off__c> sdolist;
    
	public void setempName (String empName){
		this.empName = empName;
		System.debug('This is the name' + empName);
	}
	public void setsdoType (String sdoType){
		this.sdoType = sdoType;
		System.debug('This is the type' + sdoType);
	}
	
	public void setsdoFrom (Date sdoFrom){
		this.sdoFrom = sdoFrom;
		System.debug('This is the date' + sdoFrom);
	}
	
	public void setsdoTo (Date sdoTo){
		this.sdoTo = sdoTo;
		System.debug('This is the date' + sdoFrom);
	}
	
	public PageReference deleteSDO(){
		sdolist = [SELECT ID FROM Schedule_Days_Off__c WHERE Employee_Name__c =: empName]; 
		try{
			delete sdolist;
		}
		catch(DmlException e){
		}
		return null;
	}
}

 Please help. Thank you. 

TheIntegratorTheIntegrator

could you remove the try/catch and post if gives an error, or paste the debug log here

AmitSahuAmitSahu

Try adding one line and see the result in Debug log :

sdolist = [SELECT ID FROM Schedule_Days_Off__c WHERE Employee_Name__c =: empName];
System.Debug('@@@'+sdolist);

 Check the log and let us know if you see any record in there ...


lovetolearnlovetolearn

Hi, 

 

The debug log return no records. I am not sure why though. I am sure that there are records. 

 

Please let me know where I made a mistake.