• ms Scott
  • NEWBIE
  • 20 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 3
    Replies
I have a schedulable apex process that i use to update a date field and then update all of the records. The process works great, i use the scheduler and schedule it to run every week on Tuesday's at 10pm (for 2 months or longer). It fires on Tuesday, but won't fire the 2nd week or any other time. I tried every other day, every day, no matter how many time i schedule to process...it will only fire once. Is there's something i'm missing?

Here's my code;

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;
    }
}

Thanks in Advance! (this is my first apex class)

M Scott
 
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 need a apex scheduler that will update a date field every 24 hours with the current date.

My application track students employment activities, when they start, when job ends, how many days they works, wages per day...etc.

My object name = Grad_Employment_Detail__c
My field name = current_Date__c

More details - this is my work around for not being able to use the "today ()" formula on a formula field because i'm using roll-up summary fields to tally up some key fields. The students might have work for several companies and I need to tally up how many days with each company. (hope this makes sense?)

When employment ends there's an employment start and stop date so it's easy to count the number of days worked.
When they are still working the employment end date field is blank. By creating a "current date" field I can calculate the number of days employed with current employer and add that number with former employment records and roll-up the total number of days worked.

I've tried with workflows and can't seem to get them to work properly....and it's time time for me to go to the next level in development and learn about Apex classes.

Can someone show me the code to write an Apex Trigger that will update a Date Field every 24 hours with the current date?
And I'll need the Apex test class as well.

My object name = Grad_Employment_Detail__c
My field name = current_Date__c

Would like the field to be updated every night at 1am..or anytime after nignight. (I know about the scheduler to set the time)

Thanks in Advance!
M Scott 
I've created my first Apex Scheduler Class. Tested and working like champ in sandbox. Getting failues trying to puch into production.
Class= "ChatterAnswersEscalationTriggerTest" failue;
Method Name = "validateQuestionEscalation"
Error Message = "System.QueryException: List has no rows for assignment to SObject"
"Stack Trace: Class.ChatterAnswersEscalationTriggerTest.validateQuestionEscalation: line 17, column 1"

Thanks in Advance!
Michael
I have a schedulable apex process that i use to update a date field and then update all of the records. The process works great, i use the scheduler and schedule it to run every week on Tuesday's at 10pm (for 2 months or longer). It fires on Tuesday, but won't fire the 2nd week or any other time. I tried every other day, every day, no matter how many time i schedule to process...it will only fire once. Is there's something i'm missing?

Here's my code;

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;
    }
}

Thanks in Advance! (this is my first apex class)

M Scott
 
I need a apex scheduler that will update a date field every 24 hours with the current date.

My application track students employment activities, when they start, when job ends, how many days they works, wages per day...etc.

My object name = Grad_Employment_Detail__c
My field name = current_Date__c

More details - this is my work around for not being able to use the "today ()" formula on a formula field because i'm using roll-up summary fields to tally up some key fields. The students might have work for several companies and I need to tally up how many days with each company. (hope this makes sense?)

When employment ends there's an employment start and stop date so it's easy to count the number of days worked.
When they are still working the employment end date field is blank. By creating a "current date" field I can calculate the number of days employed with current employer and add that number with former employment records and roll-up the total number of days worked.

I've tried with workflows and can't seem to get them to work properly....and it's time time for me to go to the next level in development and learn about Apex classes.

Can someone show me the code to write an Apex Trigger that will update a Date Field every 24 hours with the current date?
And I'll need the Apex test class as well.

My object name = Grad_Employment_Detail__c
My field name = current_Date__c

Would like the field to be updated every night at 1am..or anytime after nignight. (I know about the scheduler to set the time)

Thanks in Advance!
M Scott 
I've created my first Apex Scheduler Class. Tested and working like champ in sandbox. Getting failues trying to puch into production.
Class= "ChatterAnswersEscalationTriggerTest" failue;
Method Name = "validateQuestionEscalation"
Error Message = "System.QueryException: List has no rows for assignment to SObject"
"Stack Trace: Class.ChatterAnswersEscalationTriggerTest.validateQuestionEscalation: line 17, column 1"

Thanks in Advance!
Michael