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
JPSeaburyJPSeabury 

Resolving unexpected error: "Variable Does Not Exist: ArticleType"

One of my test methods is returning the following error:

Case: CaseTriggerHandlerTest
Method: test_insertSingleWebCase
Error: "line -1, column -1: Dependent class is invalid and needs recompilation: Class TestDataFactory : Variable does not exist: ArticleType"

User-added image

While it's true that "ArticleType" doesn't exist in my TestDataFactory apex class, I don't reference that variable in my CaseTriggerHandlerTest class either. The "test_insertSingleWebCase" doesn't reference one either.

Here is the method that is failing in CaseTriggerHandlerTest:

@isTest static void test_insertSingleWebCase() {
        // Mock up a test Web Case
        List<Case> testWebCases = TestDataFactory.createWebCase(1);
        System.debug('testWebCases.size: ' + testWebCases.size() + ' | ' + testWebCases);
        System.AssertEquals(testWebCases.size(), 1);
        
        Id origContactId = testWebCases[0].ContactId;
        String origSuppliedName = testWebCases[0].SuppliedName;
        insert testWebCases[0];
        
        // Query / Reload the Case so we can get the Contact ID, which was not initially provided but should auto update
        Case c = [SELECT Id, ContactId FROM Case WHERE Id = :testWebCases[0].Id];
        
        // Expected Behavior: Contact ID should not be NULL (because the Case Trigger has inserted a new contact)
        System.AssertNotEquals(c.ContactId, NULL);
        
        // Modify the SuppliedName, but add another case with the same SuppliedEmail. Verify you get same c.ContactId
        // (i.e., this should NOT have resulted in a second Contact being created)
        testWebCases = TestDataFactory.createWebCase(1); // get a new case
        testWebCases[0].SuppliedName = 'Surprise!';
        insert testWebCases[0];
        
        c = [SELECT Id, ContactId, SuppliedName FROM Case WHERE Id = :testWebCases[0].Id];
        
        System.AssertNotEquals (origContactId, c.ContactId);
        System.AssertNotEquals(origSuppliedName,c.SuppliedName);
    }


Here is the entire TestDataFactory class:

public abstract class TestDataFactory {
    
    // Account Creation
    public static List<Account> createAccounts (Integer numberOfAccounts) {
        List<Account> accounts = new List<Account>();
        for (Integer i=0 ; i < numberOfAccounts ; i++) {
            Account testAccount = new Account(Name='Test Account' + i);
            accounts.add(testAccount);
        }
		return accounts;
    }
    
    // Contact Creation
    public static List<Contact> createContacts (Account testAccount, Integer numberOfContacts) {
        List<Contact> contacts = new List<Contact>();
        for (Integer i=0; i < numberOfContacts; i++) {
            String strLastName = 'Jones'+i;
            String strEmail = strLastName+'@'+testAccount.Name+'.com';
            strEmail = strEmail.remove(' ');
            Contact testContact = new Contact(LastName=strLastName, AccountId=testAccount.Id, Email=strEmail);
            contacts.add(testContact);
        }
        return contacts;
    }
    
    // Web Case Creation
    public static List<Case> createWebCase (Integer numberOfWebCases) {
        List<Case> testCases = new List<Case>();
        Map<String, Schema.RecordTypeInfo> recordTypes = Schema.SObjectType.Case.getRecordTypeInfosByName();
        Id caseRecordType = recordTypes.get('1819 Case').getRecordTypeId();

        for (Integer i=0; i<numberOfWebCases; i++) {
            String strSuppliedName='Bob Jones'+i;
            String strSuppliedEmail='bob_jones'+i+'@randomdomain.com';
            
            Case testCase = new Case(Status = 'New', 
                                     Priority = 'Normal', 
                                     Origin = 'Email', 
                                     RecordTypeId = caseRecordType,
                           			 SuppliedEmail = strSuppliedEmail, 
                                     SuppliedName = strSuppliedName,
                           			 Subject='Test Case', 
                                     Description='This is a test. This is only a test.');
            testCases.add(testCase);
        }
        
        return testCases;
    }

}
Abhishek BansalAbhishek Bansal
Hi,

Do you have any trigger on the Case object, If yes, than please try to edit and save that trigger or if you have trigger handler class than please edit and save that handler class. This error might be coming from that trigger. 

Thanks,
Abhishek Bansal.