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
Chad MoutesChad Moutes 

Help With Scheduled Apex Class

I have a custom object called Project, and a subordinate custom object called CRM Hour Tracker, what i would like to do is create a scheduled Apex Class to create a new CRM Hour Tracker every month on the first day of that month for every Project in the system.(Only About 110). I know how to do the scheduling of the Apex Class, my problem is i need each of these CRM Hour Trackers to relate to a different Project. Anyone have any ideas?
Chad - In the batch class start method query your custom Product object and then in Excute method write the logic to insert CRM hour tracker. Check the below sample code for your logic
global class insertCRMHour implements Database.Batchable<sObject>{

   global Database.QueryLocator start(Database.BatchableContext BC){
      return Database.getQueryLocator('Select id from Product__c'); //Query the Custom Product object

   global void execute(Database.BatchableContext BC, List<Product__c> scope){
     List<CRMHour__c> listcrmHour = new List<CRMHour__c>();
     for(Product s : scope){
       crmHour__c crmhour = new crmHour__c();
       //add othe field values
       listcrmHour.add(crmhour); //Add in the list
     insert listcrmHour;

   global void finish(Database.BatchableContext BC){