• Pooja Joshi 38
  • 0 Points
  • Member since 2019

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
  • 0
I have built a scheduler test class that tests if the batch runs successfully.
When I test manually I can see the data gets populated as expected but the assertion in the scheduler test class fails.
Here is the code
public with sharing class ScheduleEmployeeBatchTest {
    static testmethod void schedulerTest() 
        String CRON_EXP = '0 0 0 15 3 ? 2022';
        // Create test data
          Employee__c emp =TestData.getNewEmployee();
          emp.EmployeeNumber__c = ‘Emp001’;
          insert emp;
        String jobId = System.schedule('ScheduleEmployeeBatchTest',  CRON_EXP, new ScheduleEmployeeBatch());
        CronTrigger ct = [SELECT Id, CronExpression, TimesTriggered, NextFireTime FROM CronTrigger WHERE id = :jobId];
            System.assertEquals(CRON_EXP, ct.CronExpression);
            System.assertEquals(0, ct.TimesTriggered);

         // verify that the employee was created successfully
                select Id
                from EmpTeam__C
                where Employee__r.Name = ‘Emp001’

I am trying to acheive this by Batch apex.

I have an external object in Salesforce which is getting data from an external system. The external object has multiple rows for each student to represent the multiple courses he/she is taking.

For each insert, update and delete I want to update Student object, Course boject and a junction object which will hold many to many relationship between Students and Courses 

For eg. if student Peter is taking two courses Math and English, that would be two rows in External object.
After the batch runs one row should be inserted into the Student object and two rows into the Course object and two rows into the Juction object.

Thanks so much.