+ Start a Discussion

how to insert new records using scheduled job

how can i insert new records and set a value for the required fields using scheduled job?
these are the objects and its fields:

  Object                              CustomFields
Position__c                  Type(picklist values:admin, tech)
Employee__c               Position__c(lookup)
PaySlip__c                   Employee__c(lookup), Date_From__c, Date_To__c

i want to insert new PaySlip__c records for every Employee whose Position type is 'Tech'
this is the code i'm using to insert new PaySlip__c and fill up the Date_From__c and Date_To__c
global class autoGenerateReport implements Schedulable {
         global void execute(SchedulableContext arc) {
                  Date dateToday = system.Today();
                  Integer month = dateToday.month();
        Integer year = dateToday.year();
                  Date firstDayOfMonth = System.today().toStartOfMonth();
                  Date firstOfMonth = date.newinstance(year, month, 1);
                  Date upToDate = date.newinstance(year, month, 15);
                  PaySlip__c createReport = new PaySlip__c();
                  createReport.Date_From__c = firstOfMonth;
                  createReport.Date_To__c = upToDate;
                   insert createReport;

Hi , 

Need some more information on this,  - Which part is not working Inserting records or Apex running at the scheduled time?

See the below link to Understand how to write the scheduled time in APX,