1

Can someone help me out with my test class, Im getting an error where it says list has no rows?

@isTest
private class dailyUpdatesMortgageTest{

    @testSetup 
    static void setup(){

        //Create mortgage setup
        List<Mortgage__c> listMortgage = new List<Mortgage__c>();

        //Create the deal setup
        TAgent__c tagent = new TAgent__c();
        tagent.Name = 'Test Tagent 3';
        tagent.Country__c = 'ID';
        tagent.CurrencyIsoCode = 'IDR';
        tagent.MemberLevel__c = 'PlatinumPRO';
        insert tagent;

        Account account = new Account();
        account.Name = 'test account';
        account.CurrencyIsoCode = 'IDR';
        account.TypeOfCompany__c = 'Agent / Broker';
        account.AccountCountry__c = 'ID';
        insert account;

        Account bankAccount = new Account();
        bankAccount.Name = 'test bank account';
        bankAccount.CurrencyIsoCode = 'IDR';
        bankAccount.TypeOfCompany__c = 'Bank';
        bankAccount.AccountCountry__c = 'ID';
        insert bankAccount;


        TLead__c tlead = new TLead__c();
        tlead.Name ='tlead test';
        tlead.Lead_Source__c = 'Retargeting';
        tlead.Country__c = 'ID'; 
        insert tlead;

        Project__c project = new Project__c();
        project.Name = 'test project';
        project.ProjectID__c = '20';
        project.Account__c = account.Id;
        project.CurrencyIsoCode = 'IDR';
        project.Country__c = 'ID';
        project.City__c = 'Jakarta';
        project.PropertyType__c = 'House';
        project.ProjectSource__c = 'PropertyPro';
        insert project;

        TDeal__c deal2 = new TDeal__c();
        deal2.RecordTypeId = '0121p000000FTbU';
        deal2.Name = 'test pp';
        deal2.TLead__c = tlead.Id;
        deal2.Project2__c = project.Id;
        deal2.LeadSource__c = 'Organic';
        deal2.ProjectSource__c = 'PropertyPro';
        deal2.CurrencyIsoCode = 'IDR';
        deal2.SalesStage__c = '5. Deal Closed';
        deal2.TAgent__c = tagent.Id;
        deal2.DateOfSigning__c = system.today();
        deal2.DealType__c = 'Booking';
        deal2.DealValue__c = 2000000000;
        deal2.ConfirmDealValue__c = TRUE;
        insert deal2;


        Mortgage__c mortgage = new Mortgage__c();
        mortgage.Name = 'Test mortgage';
        mortgage.PitchedProject__c = deal2.Id;
        mortgage.CurrencyIsoCode = 'IDR';
        mortgage.InstallmentCounter__c = 1;
        mortgage.Bank__c = bankAccount.Id;

        listMortgage.add(mortgage);
        insert listMortgage;
    } 

    @isTest 
    static void testMethod1(){

        Mortgage__c m1 = [SELECT Id FROM Mortgage__c WHERE Name = 'Test mortgage' LIMIT 1];
        m1.NextDownPayment1__c = null;

        update m1;

        Test.startTest();
        dailyUpdatesMortgage instance = new dailyUpdatesMortgage();
        instance.scheduledMortgageUpdates();
        Test.stopTest();   

    }

    @isTest 
    static void testMethod2(){

        Mortgage__c m2 = [SELECT Id FROM Mortgage__c WHERE Name = 'Test mortgage' LIMIT 1];
        m2.NextDownPayment1__c = Date.today().addDays(1);

        update m2;

        Test.startTest();
        dailyUpdatesMortgage instance = new dailyUpdatesMortgage();
        instance.scheduledMortgageUpdates();
        Test.stopTest();   

    }

    @isTest 
    static void testMethod3(){

        Mortgage__c m3 = [SELECT Id FROM Mortgage__c WHERE Name = 'Test mortgage' LIMIT 1];
        m3.NextDownPayment1__c = Date.today().addDays(-8);

        update m3;

        Test.startTest();
        dailyUpdatesMortgage instance = new dailyUpdatesMortgage();
        instance.scheduledMortgageUpdates();
        Test.stopTest();   

    }

}

1 Answer 1

0

This is because your SOQL query returns 0 record. Refer the link Check Here

Check if the Mortage record is inserted successfully in the testsetup.

5
  • Im using @testSetup and create new list object List<Mortgage__c> listMortgage = new List<Mortgage__c>(); , I assume this is supposed to be available in my testmethod no? Dec 13, 2019 at 10:14
  • It should, but in case if there is any triggers/pb/etc that renames that record or deletes it -- then it will be missing
    – kurunve
    Dec 13, 2019 at 10:20
  • hmm strange, I tested it in developer console and the Mortgage__c record is created as expected Dec 13, 2019 at 10:30
  • @AdnanZahry You can simply query- SELECT Id FROM Mortgage__c in the test method to see if the record exists, moreover you are creating a single record, it doesn't matter about the Name filter criteria Dec 13, 2019 at 10:30
  • Ah, Just realize that I have a workflow to rename the Name field in every creation, small thing missed. thanks Anand Dec 13, 2019 at 10:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .