Accounting API Developer's Reference

c2g.CronSpec

global class CronSpec

This class is used to represent a cron expression. Read http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_scheduler.htm and http://en.wikipedia.org/wiki/Cron. New crons can be generated from scratch, or can be generated from a given cron string. Each cron will be of a given type, known as a frequency type, e.g Hourly, daily, weekly.

Methods

createHourlyCron

global static c2g.CronSpec createHourlyCron(String interval, String offset)

Create a c2g.CronSpec with an hourly schedule.

Input Parameters

Name Type Description
interval String The interval at which you want the schedule to run. For example if you select 3 hours the schedule runs every 3 hours. The limit is 12 hours.
offset String The minutes past the hour that you want the schedule to run; 00, 15, 30 or 45.

Return Value

This method returns a CronSpec object.

Sample Code

//Note: This sample code is for demonstration purposes only, it is not intended for
//use in a production environment, is not guaranteed against defects or errors and
//is in no way optimized or streamlined.

c2g.CronSpec theCronSpec = c2g.CronSpec.createHourlyCron('2', '15');

createDailyCron

global static c2g.CronSpec createDailyCron(String hour)

Create a c2g.CronSpec with a daily schedule.

Input Parameters

Name Type Description
hour String The hour of the day to run the schedule on.

Return Value

This method returns a CronSpec object.

Sample Code

//Note: This sample code is for demonstration purposes only, it is not intended for
//use in a production environment, is not guaranteed against defects or errors and
//is in no way optimized or streamlined.

c2g.CronSpec theCronSpec = c2g.CronSpec.createDailyCron('0');

createWeeklyCron

global static c2g.CronSpec createWeeklyCron(String hour, String[] weekDays)

Create a c2g.CronSpec with a weekly schedule.

Input Parameters

Name Type Description
hour String The hour of the day to run the schedule on.
weekDays String[] The days of the week you want the schedule to run. For example, 1 for Sunday, 2 for Monday and so on. Enter more than one string in the array to choose multiple days.

Return Value

This method returns a CronSpec object.

Sample Code

//Note: This sample code is for demonstration purposes only, it is not intended for
//use in a production environment, is not guaranteed against defects or errors and
//is in no way optimized or streamlined.

c2g.CronSpec theCronSpec = c2g.CronSpec.createWeeklyCron('0', new String[]{'1','3','5','7'});

createMonthlyByDayOfTheMonthCron

global static c2g.CronSpec createMonthlyByDayOfTheMonthCron(String hour, String monthDay)

Create a c2g.CronSpec with a monthly schedule via a specific day of the month.

Input Parameters

Name Type Description
hour String The hour of the day to run the schedule on.
monthDay String The day of the month to run the schedule on.

Return Value

This method returns a CronSpec object.

Sample Code

//Note: This sample code is for demonstration purposes only, it is not intended for
//use in a production environment, is not guaranteed against defects or errors and
//is in no way optimized or streamlined.

c2g.CronSpec theCronSpec = c2g.CronSpec.createMonthlyByDayOfTheMonthCron('0', '1');

createMonthlyByDayOfTheWeekCron

global static c2g.CronSpec createMonthlyByDayOfTheWeekCron(String hour, String dayOccurrence, String weekday)

Create a c2g.CronSpec with a monthly schedule via a specific week day.

Input Parameters

Name Type Description
hour String The hour of the day to run the schedule on.
dayOccurrence String The selected day to run the schedule on. For example, if weekDay is Tuesday then giving dayOccurance a value of 2 will make the schedule run on the second Tuesday of the month. Choice of 1 to 4, and 'L' for last occurrence of the month.
weekday String The day of the week to run the schedule on. For example, 1 for Sunday, 2 for Monday and so on.

Return Value

This method returns a CronSpec object.

Sample Code

//Note: This sample code is for demonstration purposes only, it is not intended for
//use in a production environment, is not guaranteed against defects or errors and
//is in no way optimized or streamlined.

CronSpec theCronSpec = CronSpec.createMonthlyByDayOfTheWeekCron('0', '1', '1');

createByDate

global static c2g.CronSpec createByDate(String seconds, String minutes, String hour, String monthDay, String month, String year)

Create a c2g.CronSpec to schedule on a specific date.

Input Parameters

Name Type Description
seconds String The seconds to run the schedule on.
minutes String The minutes to run the schedule on.
hour String The hour of the day to run the schedule on.
monthDay String The day of the month to run the schedule on.
month String The month to run the schedule on.
year String The year to run the schedule on.

Return Value

This method returns a CronSpec object.

Sample Code

//Note: This sample code is for demonstration purposes only, it is not intended for
//use in a production environment, is not guaranteed against defects or errors and
//is in no way optimized or streamlined.

c2g.CronSpec theCronSpec = c2g.CronSpec.createByDate('0', '59', '7', '31', '12', '2014');

createByDate

global static c2g.CronSpec createByDate(String seconds, String minutes, String hour, Date theDate)

Create a c2g.CronSpec to schedule on a specific date.

Input Parameters

Name Type Description
seconds String The seconds to run the schedule on.
minutes String The minutes to run the schedule on.
hour String The hour of the day to run the schedule on.
theDate Date The date to run the schedule on.

Return Value

This method returns a CronSpec object.

Sample Code

//Note: This sample code is for demonstration purposes only, it is not intended for
//use in a production environment, is not guaranteed against defects or errors and
//is in no way optimized or streamlined.

c2g.CronSpec theCronSpec = c2g.CronSpec.createByDate('0', '59', '4', Date.newInstance(2014, 12, 31));

createByDate

global static c2g.CronSpec createByDate(Datetime theDate)

Create a c2g.CronSpec to schedule on a specific date.

Input Parameters

Name Type Description
theDate Datetime The datetime to run the schedule on.

Return Value

This method returns a CronSpec object.

Sample Code

//Note: This sample code is for demonstration purposes only, it is not intended for
//use in a production environment, is not guaranteed against defects or errors and
//is in no way optimized or streamlined.

c2g.CronSpec theCronSpec = c2g.CronSpec.createByDate(Datetime.newInstance(2014, 12, 31, 4, 59, 0));

parse

global static c2g.CronSpec parse(String cronString)

Parse the given cron string into a c2g.CronSpec

Input Parameters

Name Type Description
cronString String The cron expression to create a CronSpec object from.

Return Value

This method returns a CronSpec object.

Sample Code

//Note: This sample code is for demonstration purposes only, it is not intended for
//use in a production environment, is not guaranteed against defects or errors and
//is in no way optimized or streamlined.

c2g.CronSpec theCronSpec = c2g.CronSpec.parse('0 15 */2 * * ?');