-4

I Get te following error on my testclass: Method does not exist or incorrect signature: void isEmpty(). There are several answers to this but I still dont understand what is wrong with my testclass.

Class

public class CreateFactuurregel {
    public void CreateFactuurregel(){
        List<Account> acc= [SELECT Name,Debiteurenrnummer__c FROM Account WHERE Bestuurdersaansprakelijkheidsverzekering__c = true AND RecordTypeId ='0125800000010Rk'];
        for(integer x=0;x<acc.size();x++){
            Factuurregel__c fact =new Factuurregel__c(Organisatie__c=acc[x].Name, Debiteur__c = acc[x].Debiteurenrnummer__c ,
                                                      Aantal__c = 1, Product__c= 'Bestuurdersaansprakelijkheidsverzekering', Factuurdatum__c= date.today()
                                                     );
            insert fact;
        } 
    }
}

Test

@isTest
public class CreateFactuurregelTest {
    static testMethod void createFactuurregelstest() {
    Account acct = new Account(Name = 'testname', recordtypeId='0125800000010Rk',Bestuurdersaansprakelijkheidsverzekering__c=true);
    insert acct;

        CreateFactuurregel fr = new CreateFactuurregel();

        system.assert(!fr.isEmpty());
    }
}
  • 2
    Well, if you don't define that method on your class CreateFactuurregel, it will not exist. – Florian Heer Nov 29 '17 at 17:04
  • 1
    Hi Thomas, welcome to SFSE. Please take a moment to scroll through the tour, read How to Ask, and visit the help center. If you explain what you are trying to achieve, you are more likely to get a useful answer. – Adrian Larson Nov 29 '17 at 17:17
1

I'll offer a couple notes here that you may find useful.

  • Never hard-code Ids.

    Salesforce itself indicates it as a best practice to avoid such hard-coding, and it completely breaks your flexibility to migrate between orgs (except from full-copy sandbox environments to production).

    You can modify your query to filter on RecordType.DeveloperName:

    ... AND RecordType.DeveloperName = 'My_Record_Type'
    

    You can modify your test class to query for that RecordType and set its Id:

    RecordType myRecordType = [
        SELECT Id FROM RecordType
        WHERE SObjectType = 'Account'
        AND DeveloperName = 'My_Record_Type'
    ];
    insert new Account(/*other fields*/, RecordTypeId=myRecordType.Id);
    
  • Add informative assertion messages. They make your tests way easier to maintain and understand.

  • If you want to store some data outside the context of a method, you can do so by adding a property.

    For example, that might look like:

    public class MyClass
    {
        public List<Account> myAccounts;
        public MyClass()
        { // constructor block
    
            myAccounts = [/*some query*/]
    
        }
        public void myMethod()
        {
            // use myAccounts data here
        }
    }
    

    Now in your test, you can check if the proper records get queried:

    static testmethod void myTest()
    {
        // set up data
    
        Test.startTest();
            MyClass instance = new MyClass();
        Test.stopTest();
    
        system.assertNotEquals(null, instance.myAccounts, 'The collection should be initialized');
        system.assert(!instance.myAccounts.isEmpty(), 'The proper records should be queried');
    }
    

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.