You need to sign in to do that
Don't have an account?
Luison Lassala 13
Apex scheduler to update a field on a specific date each Year
I need to set the value of a custom Contact date field to a date on THAT date (e.g. set the field "Next Class Update" to "YYYY/7/1" every year on July 1st).
Searching for a solution on the Developers Community I have come across "Apex Scheduler". I've never written any Apex code and would take me ages to learn. Is there any help I can get to write this very simple "schedule": <set the field "Next Class Update" to "YYYY/7/1" on THAT date and no sooner or later>.
This change should only apply to Contact records with Record_Type = "Child".
Many thanks in advance. Luison
Searching for a solution on the Developers Community I have come across "Apex Scheduler". I've never written any Apex code and would take me ages to learn. Is there any help I can get to write this very simple "schedule": <set the field "Next Class Update" to "YYYY/7/1" on THAT date and no sooner or later>.
This change should only apply to Contact records with Record_Type = "Child".
Many thanks in advance. Luison
I have gone through your question and following is the answer :
Apex Class: DevCommunityQ1 Apex Class : ScheduleDevCommunityQ1
Developer Console execute this Script :
Explanation:
To write Apex Scheduler code you first need to write Batch class (check my DevCommunityQ1 Apex class).The Batch class have 3 parts or you can say, It is divided into three Sections.
Section 1: global Database.QueryLocator start(Database.BatchableContext Bc)
This section is used to write the query in String format.
Database.getQueryLocator(query) will execute your query and return List to Section 2.
Section 2: global void execute(Database.BatchableContext Bc,List<Contact> contList)
This section will allow you do all the manipulation
Section 3: global void finish(Database.BatchableContext Bc)
This section is just use for cleanup purpose.You have to another Apex class that will schedule your Batch class (Go through the ScheduleDevCommunityQ1 Apex Class) , but you haven't executed any of your Code. Now What you need to do is in Developer Console you have to execute the following Script: The System.Schedule method takes three arguments: a name for the job, an expression used to represent the time and date the job is scheduled to run, and the third argument will be object of the your Schedule class because it has the object of the Batch Class.
Hope it will work for you.
Regards,
Akshay
I will test it and confirm whether it worked or not.