I'm at a loss. I don't understand why my test class works fine in the sandbox (100% coverage), yet when I run a deployment validation in production, I get the following error for each test method:
System.QueryException: List has no rows for assignment to SObject Stack Trace: Class.contentDocumentLinkTriggerTest.internalResolutionNote: line 53, column 1
(This is the first SOQL query in each test method attempting to return the relevant ContentNote inserted in Test Setup.)
@IsTest
public class contentDocumentLinkTriggerTest {
@TestSetup static void setupData() {
Case internalCase = new Case(Subject = 'TestContentDocumentTriggerInternalCase',
Description = 'test description',
RecordTypeId = [Select Id
From RecordType
Where DeveloperName = 'Internal_Case'
Limit 1].Id,
Type = 'Bug',
Status = 'Backlog',
Origin = 'Admin',
Priority = 'P3 - Minor',
HasResolutionNotes__c = False);
Case customerCase = new Case(Subject = 'TestContentDocumentTriggerCustomerCase',
Description = 'test description',
RecordTypeId = [Select Id
From RecordType
Where DeveloperName = 'Customer'
Limit 1].Id,
Type = 'Bug',
Status = 'Open',
Origin = 'Email',
Priority = 'Medium',
HasResolutionNotes__c = False);
ContentNote cnResolution = new ContentNote(Title = 'Resolution Notes TriggerTest',
OwnerId = [Select Id
From User
Where IsActive = True
And CompanyName Like '%[our company name]%'
Limit 1].Id);
ContentNote cnNoResolution = new ContentNote(Title = 'Some Different Notes TriggerTest',
OwnerId = [Select Id
From User
Where IsActive = True
And CompanyName Like '%[our company name]%'
Limit 1].Id);
insert internalCase;
insert customerCase;
insert cnResolution;
insert cnNoResolution;
}
@IsTest
static void internalResolutionNote() {
ContentNote cnResolution = [Select Id
From ContentNote
Where Title = 'Resolution Notes TriggerTest'
Limit 1];
Case internalCase = [Select Id
From Case
Where Subject = 'TestContentDocumentTriggerInternalCase'
Limit 1];
ContentDocumentLink cdl = new ContentDocumentLink(ContentDocumentId = cnResolution.Id,
LinkedEntityId = internalCase.Id,
ShareType = 'I');
Test.startTest();
insert cdl;
Test.stopTest();
Case checkCase = [Select Id, HasResolutionNotes__c
From Case
Where Subject = 'TestContentDocumentTriggerInternalCase'];
System.assert(checkCase.HasResolutionNotes__c);
}
@IsTest
static void customerResolutionNote() {
ContentNote cnResolution = [Select Id
From ContentNote
Where Title = 'Resolution Notes TriggerTest'
Limit 1];
Case customerCase = [Select Id
From Case
Where Subject = 'TestContentDocumentTriggerCustomerCase'
Limit 1];
ContentDocumentLink cdl = new ContentDocumentLink(ContentDocumentId = cnResolution.Id,
LinkedEntityId = customerCase.Id,
ShareType = 'I');
Test.startTest();
insert cdl;
Test.stopTest();
Case checkCase = [Select Id, HasResolutionNotes__c
From Case
Where Subject = 'TestContentDocumentTriggerCustomerCase'];
System.assert(!checkCase.HasResolutionNotes__c);
}
@IsTest
static void internalNoResolutionNote() {
ContentNote cnNoResolution = [Select Id
From ContentNote
Where Title = 'Some Different Notes TriggerTest'
Limit 1];
Case internalCase = [Select Id
From Case
Where Subject = 'TestContentDocumentTriggerInternalCase'
Limit 1];
ContentDocumentLink cdl = new ContentDocumentLink(ContentDocumentId = cnNoResolution.Id,
LinkedEntityId = internalCase.Id,
ShareType = 'I');
Test.startTest();
insert cdl;
Test.stopTest();
Case checkCase = [Select Id, HasResolutionNotes__c
From Case
Where Subject = 'TestContentDocumentTriggerInternalCase'];
System.assert(!checkCase.HasResolutionNotes__c);
}
@IsTest
static void customerNoResolutionNote() {
ContentNote cnNoResolution = [Select Id
From ContentNote
Where Title = 'Some Different Notes TriggerTest'
Limit 1];
Case customerCase = [Select Id
From Case
Where Subject = 'TestContentDocumentTriggerCustomerCase'
Limit 1];
ContentDocumentLink cdl = new ContentDocumentLink(ContentDocumentId = cnNoResolution.Id,
LinkedEntityId = customerCase.Id,
ShareType = 'I');
Test.startTest();
insert cdl;
Test.stopTest();
Case checkCase = [Select Id, HasResolutionNotes__c
From Case
Where Subject = 'TestContentDocumentTriggerCustomerCase'];
System.assert(!checkCase.HasResolutionNotes__c);
}
}