I am facing the below error in my test class.
System.QueryException: List has no rows for assignment to SObject'
I get this error on the following line in my test class:
InsolvencyPopupMessage Insolvpop = new InsolvencyPopupMessage(sc);
Apex Class
public class InsolvencyPopupMessage {
public String insolvencyAccntId{get;set;}
public Boolean sentToCollections {get;set;}
public Insolvency_Account__c insolvncyAccnt{get;set;}
public InsolvencyPopupMessage(ApexPages.StandardController controller){
//Insolvency Account ID
insolvencyAccntId = ApexPages.currentPage().getParameters().get('id');
//Insolvency Account record
insolvncyAccnt = [SELECT Id,Name,Accepted_Sent_to_Collections__c,Insolvency_Status__c
FROM Insolvency_Account__c WHERE Id =: insolvencyAccntId limit 1];
if(insolvncyAccnt.Accepted_Sent_to_Collections__c == true && insolvncyAccnt.Insolvency_Status__c!='Sent to collections'){
senttocollections = true;
}
}
public PageReference displayPopup() {
PageReference newPage;
if(insolvncyAccnt.Insolvency_Status__c!='Sent to collections'){
/*newPage = New PageReference('/apex/InsolvencyAccntPopUp');
newPage.getParameters().put('id',ApexPages.currentPage().getParameters().get('id'));
newPage.setRedirect(true);*/
return null;
}else{
newPage = New PageReference('/apex/InsolvencyAccountView');
newPage.getParameters().put('id',ApexPages.currentPage().getParameters().get('id'));
newPage.setRedirect(true);
return newPage;
}
}
}
Test Class
@istest
public class TestInsolvencyPopupMessage {
@istest
public static void TestInsolvencyPopupMessage()
{
Insolvency__c insolv=new Insolvency__c();
insolv.Insolvency_Type__c='Bankruptcy';
insolv.Insolvency_Status__c='Staging';
insolv.Name='35-1415724';
insolv.Debtor_1_Court_Number__c='12';
insolv.Court_Division_Number__c='1014';
insolv.Court_District_Name__c='101';
insolv.Court_Province__c='Alberta';
insolv.Insolvency_Received_Date__c=system.today();
insolv.Insolvency_Date__c=system.today();
insolv.Debtor_1_First_Name__c='dummy';
insolv.Debtor_1_Last_Name__c='dummy2';
insolv.Debtor_1_Date_of_Birth__c=Date.newInstance(1994, 12, 9);
insolv.Debtor_1_Gender__c='Male';
insolv.Debtor_1_Mailing_Street__c='dummy text';
insolv.Debtor_1_Mailing_City__c='Toronto';
insolv.Debtor_1_Mailing_State_Province__c='Ontario';
insolv.Debtor_1_Mailing_Postal_Code__c='N2T2X6';
Insert insolv;
RecordType rt=[select id,Name from RecordType where Name='Scotia Bank Insolvency Account' and sObjectType='Insolvency_Account__c' limit 1];
Insolvency_Account__c insolvncyAccnt=new Insolvency_Account__c();
insolvncyAccnt.RecordTypeId=rt.id;
insolvncyAccnt.Name='1056649437375';
insolvncyAccnt.Account_Type__c='Unknown';
insolvncyAccnt.Insolvency_Status__c='New';
insolvncyAccnt.Borrower_Primary__c='test';
insolvncyAccnt.Type_of_Service__c='Service and Sale';
insolvncyAccnt.Claim_Type__c='Unsecured';
Insert insolvncyAccnt;
insolvncyAccnt.Insolvency_Status__c='Sent to collections';
update insolvncyAccnt;
ApexPages.StandardController sc = new ApexPages.standardController(insolvncyAccnt);
InsolvencyPopupMessage Insolvpop = new InsolvencyPopupMessage(sc);
Insolvpop.displayPopup();
}
}