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
Sue IrvineSue Irvine 

No Apex test class named 'TestRestrictContactByName' was found

I'm trying to complete the "Testing Apex Triggers" challenge. My Test class is working and has 100% code covereage but Trailhead keeps telling me "No Apex test class named 'TestRestrictContactByName' was found". There is no namespace in my de org. I'd appreciate any help in completing this challenge - it looks like it should be working. Thanks!
 
@isTest
public class TestRestrictContactByName {
    @isTest static void TestRestrictContact() {
             
        Contact con2 = New Contact(lastname='INVALIDNAME', firstname='tom');
        
        Test.startTest();
        Database.saveresult result = Database.insert(con2, false);
        Test.stopTest();

        System.assert(!result.isSuccess());
        System.assert(result.getErrors().size() > 0);
        System.assertEquals('The Last Name "'+con2.lastname+'" is not allowed for DML',
                             result.getErrors()[0].getMessage());
    }
    @isTest static void TestValidContact(){
        Contact con = new Contact(lastname='jones',firstname='tom');

        Test.startTest();
        Database.saveresult result2 = Database.insert(con,false);
        Test.stopTest();
        System.assert(result2.isSuccess());
        System.assert(result2.getErrors().size() <1);
    
}    
}



 
Maelle Polak 2Maelle Polak 2
The question is 1 year old, but i thought I would comment for any person having the same issue. Test your class using the Apex Test Execution of you Setup menu instead of the dev console. You should be able to complete your challenge. This trick seems to be applicable in many other Trailhead challenges as well. Happy learning!
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