I've had this code working in my account for a year now. When I run a test in the Developer console, no errors are generated. But when I package it up for distribution I get an error: System.ListException: List index out of bounds: 0 Class.TTCreateCampaignMemberStatus.CampaignInsert: line 6, column 1
From what I've read it seems I need to account for the situation that the list returns zero values. Would love some advice on how to fix this. Here is the code:
@isTest
private class TTCreateCampaignMemberStatus
{
static testMethod void CampaignInsert() {
List<RecordType> rt = [select Id, name from RecordType where SobjectType = 'Campaign' and name = 'Events and Meetings'];
Campaign testCampaign = new Campaign(Name='Test Test Campaign',RecordTypeId=rt[0].Id);
insert testCampaign;
Integer i =[Select count() FROM CampaignMemberStatus WHERE CampaignID=:testCampaign.id];
System.assertEquals(5,i);
}
}