I'm new to this process and struggling with a simple trigger. I created a trigger to create a task based on the status of an application. I have it working in the sandbox, but when I tried to create it in production, it stated I needed a test class. Now I am stuck. I am including the code for the trigger as well as the test class.
Trigger:
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<Task> followupTasks = new List<Task>();
// 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;
}
}
Test class:
@isTest
private class RecruiterAppReviewTest {
static testMethod void myUnitTest() {
// Get Student
Contact c1 = [Select Name from Contact where Student_Type__c = 'Freshman' limit 1];
// Create Application
Application__c a1 = new Application__c(
Student__c = c1.Id,
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();
}
}
The test class is not compiling because it says Contact c1 (Get Student) System.QueryException:List has no rows for assignment to SObject. When I execute the same statement in the schema in Eclipse, it returns the one row that I expected. Any help would be greatly appreciated. Thank you.