You need to sign in to do that
Don't have an account?
mars1 Rover
Database.query is not returning data
I am new in salesforce, I have a problem with Database.query. Its not returning the data to apex class, But while i am using query editor its showing the correct data. My query is
Any help would be appreciatable
List<CM_Group__c> e = Database.query('SELECT CM_Skill_Level__c,CM_Start_Date__c,Name FROM CM_Employee__c where CM_Start_Date__c != null'); System.debug(e);when iam checking with debug log it showing empty. But when i am using query editor it showing the below result
Any help would be appreciatable
global void execute(){
List<CM_Employee__c> e = Database.query('SELECT CM_Skill_Level__c,CM_Start_Date__c,Name FROM CM_Employee__c where CM_Start_Date__c != null');
System.debug('Entered in execute');
System.debug(e);
for(CM_Employee__c emp : scope){
System.debug(emp.CM_Start_Date__c);
if(emp.CM_Start_Date__c != null){
integer diff = emp.CM_Start_Date__c.daysBetween(Date.today());
integer totalYear = diff/365;
if(totalYear < 1){
emp.CM_Skill_Level__c = 'Junior';
}else if(totalYear >= 1 && totalYear <3){
emp.CM_Skill_Level__c = 'Semi Senior';
}else if(totalYear >= 3 && totalYear <6){
emp.CM_Skill_Level__c = 'Senior';
}else if(totalYear >= 6 && totalYear <10 ){
emp.CM_Skill_Level__c = 'Expert';
}
totalRecordUpdated++;
e.add(emp);
}
}
if(e != null && e.size()>0){
update e;
}
}
}
Please try the Query by Changing your Sobject List type.
List<CM_Employee__c> e = Database.query('SELECT CM_Skill_Level__c,CM_Start_Date__c,Name FROM CM_Employee__c where CM_Start_Date__c != NULL');
System.debug(e);
Hope it'll help you!
Thanks
DineshKumar