You need to sign in to do that
Don't have an account?
ms Scott
Can't push Scheduler Class Apex into Production
Hey, I was given this code to update a date field every night and it works great in my sandbox. But the code they gave me to use for Test Class is not working and giving me errors.
I really need to get this code into production ASAP.
Scheduler Class that's working in my Sandbox;
global class SchedulerToUpdateDate implements Schedulable {
List<Grad_Employment_Detail__c> allRec = new List<Grad_Employment_Detail__c>();
List<Grad_Employment_Detail__c> toUpdate = new List<Grad_Employment_Detail__c>();
global void execute(SchedulableContext sc){
allRec = [select id, current_Date__c from Grad_Employment_Detail__c];
for(Grad_Employment_Detail__c ge: allRec){
ge.current_Date__c = date.today();
toUpdate.add(ge);
}
update toUpdate;
}
}
This is the Test Class that was given, it's not working and giving error. (errors) is at the botom of the code listed)
@IsTest
public class SchedulerToUpdateDate_Test{
public static testmethod void unitTest(){
Test.starttest();
Grad_Employment_Detail__c to = new Grad_Employment_Detail__c ();
to.current_Date__c = date.today();
insert to;
SchedulerToUpdateDate wau = new SchedulerToUpdateDate();
String sch = '0 00 1 3 * ?';
system.schedule('Test', sch, wau);
test.stoptest();
}
}
The error(s) I'm getting when trying to push into production. I specified this test only;
Method Name = unitTest
Error Message;
System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Grad_Employment_Details__c]: [Grad_Employment_Details__c]
Stack Trace: Class.SchedulerToUpdateDate_Test.unitTest: line 7, column 1
I really need to get this code into production ASAP.
Scheduler Class that's working in my Sandbox;
global class SchedulerToUpdateDate implements Schedulable {
List<Grad_Employment_Detail__c> allRec = new List<Grad_Employment_Detail__c>();
List<Grad_Employment_Detail__c> toUpdate = new List<Grad_Employment_Detail__c>();
global void execute(SchedulableContext sc){
allRec = [select id, current_Date__c from Grad_Employment_Detail__c];
for(Grad_Employment_Detail__c ge: allRec){
ge.current_Date__c = date.today();
toUpdate.add(ge);
}
update toUpdate;
}
}
This is the Test Class that was given, it's not working and giving error. (errors) is at the botom of the code listed)
@IsTest
public class SchedulerToUpdateDate_Test{
public static testmethod void unitTest(){
Test.starttest();
Grad_Employment_Detail__c to = new Grad_Employment_Detail__c ();
to.current_Date__c = date.today();
insert to;
SchedulerToUpdateDate wau = new SchedulerToUpdateDate();
String sch = '0 00 1 3 * ?';
system.schedule('Test', sch, wau);
test.stoptest();
}
}
The error(s) I'm getting when trying to push into production. I specified this test only;
Method Name = unitTest
Error Message;
System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Grad_Employment_Details__c]: [Grad_Employment_Details__c]
Stack Trace: Class.SchedulerToUpdateDate_Test.unitTest: line 7, column 1
Hi Scott,
Please follow this class, it will help you :)
All Answers
Hi Scott,
Please do below two approach and let me know the results : -
1.
2. You need to include required field from sObject - "Grad_Employment_Detail__c"
Grad_Employment_Detail__c to = new Grad_Employment_Detail__c ();
to.current_Date__c = date.today();
to.RequiredFieldName = blablabla;
Thanks
Rajat Maheshwari
rajatzmaheshwari@gmail.com
Hi Scott,
Please follow this class, it will help you :)