We have an old Salesforce org from which we are migrating entitlements and data to a new org. There is also a trigger for adding the entitlement by default to the case. It had 90% code coverage. But when I try to replicate it in our current sandbox to move it to production, it gives the above error.
Here are the trigger and the test class. Any help would be greatly appreciated.
List <Entitlement> entlsAnglo = [Select e.Id
From Entitlement e
Where e.Name = 'Anglo - Platinum'];
if(entlsAnglo.isEmpty()== false){
for (Entitlement curAngloEnt : entlsAnglo){
if (c.EntitlementId == curAngloEnt.id){
BusinessHours AngloBusinessHours = [select Id from BusinessHours where Name = 'Brisbane Business Hours' limit 1];
c.BusinessHoursId = AngloBusinessHours.id;
}
}
}
Test Class:
static testMethod void testtrigger2(){
Account acc=New Account(Name='Test');
insert acc;
Entitlement entl = [select id from Entitlement Where Name = 'Anglo - Platinum'limit 1];
Contact oContact = new Contact(FirstName='Test',LastName='test2',Email='[email protected]',Accountid=acc.id,Phone='1111111111',MobilePhone='11111111111');
insert oContact;
DateTime DT=DateTime.Now();
RecordType RT=[Select id from RecordType where Name='Software Support Case' and SObjectType='Case' limit 1];
Case c=new Case(RecordTypeID=RT.ID, Subject='test', Description='Test',Reported_At__c=DT,Responded_At__c=DT,Priority='Medium',
ContactID=oContact .id, Status='Assigned',Origin='Web',Product_Family__c='Operations',Case_Type__c='Workshop repair/RMA',
SlaStartDate=DT,Accountid=acc.id
);
insert c;
}
BusinessHours
in a unit test relies on the Business Hours records that are configured in your org. They are not isolated like other data for unit tests. Create Business Hours records in your new orgs prior to migrating this test code.