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
pvandepvande 

APEX CLASS - Failure Stack Trace

I AM RECEIVING THIS ERROR MESSAGE:

 

 

Failure Message: "System.DmlException: Insert failed. First exception on row 0; first error: INACTIVE_OWNER_OR_USER, operation performed with inactive user: []", Failure Stack Trace: "Class.TestEventDivisionUpdate.testEventDivisionUpdate: line 13, column 1"

 

WHEN I DEPLOY AN UPDATE TO AN EXISTING TRIGGER USING THIS CLASS:

CAN SOMEONE PLEASE HELP ME UNDERSTAND WHY I WOULD GET A "FAILURE STACK TRACE"?  THANK YOU!

 

@isTest
private class TestEventDivisionUpdate {
//This test will also test the Account and Contact Trigger

    static testMethod void testEventDivisionUpdate() {
        
        // Create a User, an Account and a Contact for testing purposes
       
        User u = [SELECT Id, Division, Department from User
            WHERE Division <> null AND Department <> null LIMIT 1];
            
        Account a = new Account(Name = 'Test Account', OwnerId=u.Id);
        insert a;  
        Contact c = new Contact(LastName='Test', AccountId=a.Id, OwnerId=u.Id);
        insert c;
        
        datetime StartDate = datetime.newInstance (2011, 5, 27);
        datetime EndDate = StartDate.addDays(2);
        
        Event e = new Event(Subject = 'TestSubject', OwnerId=u.Id, WhoId = c.Id, StartDateTime = StartDate, EndDateTime=EndDate);
        insert e;    
      
        Event updatedE = [SELECT Id, Department__c
            FROM Event WHERE Id = :e.Id LIMIT 1];
        
        Account UpdatedA = [SELECT Id, Department__c
            FROM Account WHERE Id = :a.Id LIMIT 1];
            
            Contact UpdatedC = [SELECT Id, ePrize_Department__c
            FROM Contact WHERE Id = :c.Id LIMIT 1];
            
        // Now do the assertions
    //    System.assertEquals(updatedE.Department__c, u.Department);
      //  System.assertEquals(updatedA.Department__c, u.Department);
        // System.assertEquals(updatedC.ePrize_Department__c, u.Department);

Best Answer chosen by Admin (Salesforce Developers) 
Andrew WilkinsonAndrew Wilkinson

Normally you should create the objects you are using in your testMethod.

 

Create the user using the following code. Insert a profile name in the query.

String profileId;
        try
        {
            profileId = [SELECT Id FROM Profile WHERE Name like: '%'+'put a profile name here'+'%' limit 1].Id;
        }
        catch(Exception ex)
        {
            System.debug(ex);
            System.assert(false, 'No profile exists with name '+ profileName);
        }
UserName = 'test'; User u = new User(); u.LastName = 'test ' + UserName; u.Alias = UserName; u.Email = UserName+'@viterahealthcare.com'; u.Username = UserName+UserName+'@test.com'; u.CommunityNickname = 'a'+UserName; u.TimeZoneSidKey = 'America/New_York'; u.LocaleSidKey = 'en_US'; u.EmailEncodingKey = 'ISO-8859-1'; u.ProfileId = profileId; u.LanguageLocaleKey = 'en_US'; u.IsActive = true; insert u;

 

All Answers

SabrentSabrent

put a debug statement after this line and get the user id.  Appears like the user this statement is fetching is no more active in the system.

 

User u = [SELECT Id, Division, Department from User
            WHERE Division <> null AND Department <> null LIMIT 1];

Andrew WilkinsonAndrew Wilkinson

Normally you should create the objects you are using in your testMethod.

 

Create the user using the following code. Insert a profile name in the query.

String profileId;
        try
        {
            profileId = [SELECT Id FROM Profile WHERE Name like: '%'+'put a profile name here'+'%' limit 1].Id;
        }
        catch(Exception ex)
        {
            System.debug(ex);
            System.assert(false, 'No profile exists with name '+ profileName);
        }
UserName = 'test'; User u = new User(); u.LastName = 'test ' + UserName; u.Alias = UserName; u.Email = UserName+'@viterahealthcare.com'; u.Username = UserName+UserName+'@test.com'; u.CommunityNickname = 'a'+UserName; u.TimeZoneSidKey = 'America/New_York'; u.LocaleSidKey = 'en_US'; u.EmailEncodingKey = 'ISO-8859-1'; u.ProfileId = profileId; u.LanguageLocaleKey = 'en_US'; u.IsActive = true; insert u;

 

This was selected as the best answer
pvandepvande

Thank you for the help; I will try to add that code to my CLASS.