Skip to main content
Tweeted twitter.com/#!/StackSalesforce/status/381800232360878080
added 130 characters in body
Source Link
Rao
  • 16.8k
  • 13
  • 69
  • 108

@isTest private class RecruiterAppReviewTest {

@isTest
private class RecruiterAppReviewTest {

    static testMethod void myUnitTest() {
        // Create Student
        Contact c1 = new Contact(
               FirstName = 'Test',
               LastName = 'TestStudent');
               
        insert c1;
        
        //Id contact_id = [Select c.Id from Contact c where c.LastName = 'TestStudent' limit 1];
        
        // Create Application
        Application__c a1 = new Application__c(
               Student__c = [Select c.Id from Contact c where c.LastName = 'TestStudent' limit 1],
               Student_Type__c = 'First Time UG',
               Full_or_Part_Time__c = 'Full-Time',
               Active_Application__c = true,
               Application_Status__c = 'Incomplete-Items Missing');
               
        insert a1;
        
        // Test Task
        test.startTest();
        
        a1.Application_Status__c = 'Complete and Ready for Review';
        update a1;
        
        test.stopTest();
    }
}

}

@isTest private class RecruiterAppReviewTest {

static testMethod void myUnitTest() {
    // Create Student
    Contact c1 = new Contact(
           FirstName = 'Test',
           LastName = 'TestStudent');
           
    insert c1;
    
    //Id contact_id = [Select c.Id from Contact c where c.LastName = 'TestStudent' limit 1];
    
    // Create Application
    Application__c a1 = new Application__c(
           Student__c = [Select c.Id from Contact c where c.LastName = 'TestStudent' limit 1],
           Student_Type__c = 'First Time UG',
           Full_or_Part_Time__c = 'Full-Time',
           Active_Application__c = true,
           Application_Status__c = 'Incomplete-Items Missing');
           
    insert a1;
    
    // Test Task
    test.startTest();
    
    a1.Application_Status__c = 'Complete and Ready for Review';
    update a1;
    
    test.stopTest();
}

}

@isTest
private class RecruiterAppReviewTest {

    static testMethod void myUnitTest() {
        // Create Student
        Contact c1 = new Contact(
               FirstName = 'Test',
               LastName = 'TestStudent');
               
        insert c1;
        
        //Id contact_id = [Select c.Id from Contact c where c.LastName = 'TestStudent' limit 1];
        
        // Create Application
        Application__c a1 = new Application__c(
               Student__c = [Select c.Id from Contact c where c.LastName = 'TestStudent' limit 1],
               Student_Type__c = 'First Time UG',
               Full_or_Part_Time__c = 'Full-Time',
               Active_Application__c = true,
               Application_Status__c = 'Incomplete-Items Missing');
               
        insert a1;
        
        // Test Task
        test.startTest();
        
        a1.Application_Status__c = 'Complete and Ready for Review';
        update a1;
        
        test.stopTest();
    }
}
Source Link
user2569499
  • 1k
  • 2
  • 13
  • 23

Problem trying to generate test class for trigger part 2

So I encapsulated the objects within the test, but still having an issue that doesn't make sense...

To recap, the trigger is: trigger RecruiterAppReview on Application__c (after update) { /****************

  • When an application status is changed to 'complete and ready for review' and the

  • application has not been withdrawn, a task needs to be created for the recruiter to

  • review the application. ****************/

    List followupTasks = new List(); // Generate a list of tasks to be generated for (Application__c appl : System.Trigger.new) { if (appl.Application_Status__c == 'Complete and Ready for Review' && appl.Withdrawal_Reason__c == null) {

         Task tasks = new Task(
                 WhoId = appl.Counselor_Id__c,
                 Description = 'Review Application',
                 Priority = 'High',
                 ReminderDateTime = System.now().addDays(3),
                 Status = 'Not Started',
                 Subject = 'Application Review');
     }
    

    } // insert the entire list if (followupTasks.size() > 0) { insert followupTasks; } }

The new test class is:

@isTest private class RecruiterAppReviewTest {

static testMethod void myUnitTest() {
    // Create Student
    Contact c1 = new Contact(
           FirstName = 'Test',
           LastName = 'TestStudent');
           
    insert c1;
    
    //Id contact_id = [Select c.Id from Contact c where c.LastName = 'TestStudent' limit 1];
    
    // Create Application
    Application__c a1 = new Application__c(
           Student__c = [Select c.Id from Contact c where c.LastName = 'TestStudent' limit 1],
           Student_Type__c = 'First Time UG',
           Full_or_Part_Time__c = 'Full-Time',
           Active_Application__c = true,
           Application_Status__c = 'Incomplete-Items Missing');
           
    insert a1;
    
    // Test Task
    test.startTest();
    
    a1.Application_Status__c = 'Complete and Ready for Review';
    update a1;
    
    test.stopTest();
}

}

Problem is with trying to assign Student__c to [Select c.Id from Contact c where c.LastName = 'TestStudent' limit 1]. I am getting Invalid initial expression type for field Application__c.Student__c, expecting: Id. I thought that is what I was giving it...

Any help would be greatly appreciated. Thank you.