function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jon FoyJon Foy 

Can I Create a Trigger that Inserts a New Record Every Month?

We have a custom object called "Case_Resource__c".

Is there a way to have a trigger run on a monthly basis (say the first of every month) as long as the following critera are true for the Case_Resource__c record:
1. UOM__c = "mo."
2. Active__c = true

And if so, to have that trigger create a new record for a different custom Object "TimeSlip__c" using fields from the Case_Resource__c object?

Again, looking for this trigger to fire automatcially every month and create a new "TimeSlip" so long as the "Case Resource" record has a UOM of "mo.", and is checked active.
Best Answer chosen by Jon Foy
Justin JulicherJustin Julicher
Hi Jon

You wouldn't do that with a Trigger you could do that with Scheduled Apex. 

Refer to http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_scheduler.htm (http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_scheduler.htm" target="_blank) for more information on how to write a scheduled class.
You can then query for the cases in question over the last month and create the records you want.

If you think you will need to query more than 50k records or create more than 10,000 cases you can use the Scheduled Apex class to call a Batch class. 

To Schedule Apex through the interface go to Setup -> Develop --> Apex Classes --> Click the button 'Schedule Apex' and you will be presented with the screenshot below where you can select the frequency of 'Monthly'.

Scheduled Apex