You need to sign in to do that
Don't have an account?

Help with Apex Class to be scheduled to just edit/save (touch) all records of a custom object given a set criteria
Hi There,
I am trying to write an APEX Class to be scheduled every year on March 1st and September 1st at 12am that will go out and edit/save all records of a customer object (Personnel_Management__C). The reason for the requirement is that we have semi-annual audit that needs to be performed on our employee information. Nothing needs to be updated, but there is a process/flow behind the scenes that I want to have triggered so that the automated approval processes and other business processes that are included in the process run. The only way I can see this happening is for an update to be made to each record that would require an audit - scheduled apex.
the customer object in question is Personnel_Management__C - At any given audit, 100+ records could qualify for the select statement for an update (keep in mind, I just want to edit and then save each record, not actually change any values).
The criteria to be met is that within Personnel_Management__C there is a picklist field that is called Employment_Status__C. This field needs to be "Current Employee" in order for it to qualify for the select statement.
I really appreciate your time and effort to help me get this done - thanks in advance (I am hoping this is quite simple and will serve as a great learning experience for me).
I am trying to write an APEX Class to be scheduled every year on March 1st and September 1st at 12am that will go out and edit/save all records of a customer object (Personnel_Management__C). The reason for the requirement is that we have semi-annual audit that needs to be performed on our employee information. Nothing needs to be updated, but there is a process/flow behind the scenes that I want to have triggered so that the automated approval processes and other business processes that are included in the process run. The only way I can see this happening is for an update to be made to each record that would require an audit - scheduled apex.
the customer object in question is Personnel_Management__C - At any given audit, 100+ records could qualify for the select statement for an update (keep in mind, I just want to edit and then save each record, not actually change any values).
The criteria to be met is that within Personnel_Management__C there is a picklist field that is called Employment_Status__C. This field needs to be "Current Employee" in order for it to qualify for the select statement.
I really appreciate your time and effort to help me get this done - thanks in advance (I am hoping this is quite simple and will serve as a great learning experience for me).
Please find the below class:
Here I considered:
(1) Exception Handling
(2) Sending an email to Admin with number of Batches processed.
(3) Used Database.update, because if there is an error in updating 1 records, all the remaining records should proceed.
Here is the Test Class:
Please do let me know if helps you.
Regards,
Mahesh
All Answers
Hope this helps!
Please find the below class:
Here I considered:
(1) Exception Handling
(2) Sending an email to Admin with number of Batches processed.
(3) Used Database.update, because if there is an error in updating 1 records, all the remaining records should proceed.
Here is the Test Class:
Please do let me know if helps you.
Regards,
Mahesh
Thank you very much - Mahesh - this was a great write up for code and testing with great comments. I learned a lot from this exercise and your code was able to accomplish exactly what I needed. I was even able to add a few more actions and remove them from other workflows.
Thanks a ton!
Cheers,
Scott