function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Matthew Holliday 8Matthew Holliday 8 

"No Apex test class named 'TestRestrictContactByName' was found" even though class exists.

I get the following message when checking the challenge for the "Testing Apex Triggers" section:

"Challenge Not yet complete... here's what's wrong: 
No Apex test class named 'TestRestrictContactByName' was found"

I've verified that there is a public class with this exact name. What am I missing?
 
@isTest
public class TestRestrictContactByName {
    public static testMethod void TestRestrictContactByNameTrigger(){
        Contact c = new Contact(LastName = 'INVALIDNAME');
    Test.startTest();
        Database.SaveResult result = Database.insert(c,false);
        Test.stopTest();
        
        System.assert(!result.isSuccess());
    }

The class is visible to all user profiles. 
Naresh YadavNaresh Yadav
Hi Matthew Holliday

Have you run all test before submit.
Amit Chaudhary 8Amit Chaudhary 8
Please delete above class and recreate .. Let us know if that will work
Rohit K SethiRohit K Sethi
Hi Matthew Holliday

Previously I am also facing same problem. And that I was doing following steps :

Salesforce Quick Findbox - > write "apex test Execution" - > select tests Buttton and find your class here.
I thing the class can be shown here. If the test class is find then execute it and then go to Dev console then search the test class.

If you are not still find the class name in test execution then open your class in read mode and there is a button run test. You can run your test class from here.

Thanks.
Tiago WelterTiago Welter
Hello, try this:
 
@isTest
public class TestRestrictContactByName {
    
    @isTest static void TestRestrictContactByNameValid() {
        
        List<Contact> ctt = new List<Contact>();
        
        ctt.add(new Contact(LastName='Welter',FirstName = 'Tiago'));
        ctt.add(new Contact(LastName='AAA'));
        ctt.add(new Contact(LastName='INVALIDNAME',FirstName = 'Tiago'));
       	ctt.add(new Contact());
        
        Test.startTest();
        Database.SaveResult[] result = Database.insert(ctt, false);
        Test.stopTest();
        
        for(Database.SaveResult sr : result){
            if(!sr.isSuccess()){
                System.assert(!sr.isSuccess());
            }else{
                System.assert(sr.isSuccess());
            }
        }
        
    }    

}

Tiago Welter
bhrigu mahajan 9bhrigu mahajan 9
@isTest
public class TestRestrictContactByName {

    @isTest static void TestRestrictContactByInvalidName() {
            Contact cont = new Contact(LastName='INVALIDNAME');
            Test.startTest();
             Database.SaveResult result = Database.insert(cont,false);
            Test.stopTest();
        
            System.assert(!result.isSuccess());
            System.assert(result.getErrors().size() > 0);
            System.assertEquals('The Last Name "'+cont.LastName+'" is not allowed for DML',
                             result.getErrors()[0].getMessage());
    }
}