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
goutham.tatineni1.3893010493585044E12goutham.tatineni1.3893010493585044E12 

Old Test Class passes in UAT fails in Production

Hi Something strange happening all of a sudden .I am trying to deploy some code to proiduction and i am having 4 ols test classes failuers . All those classes were not modified recently nor any new validations or workfl;ows around them . Could some one help me out please
All my test classes are failing with same erorr System.QueryException: List has no rows for assignment to SObject
@isTest
private class TestUpdateEvents {
    
    private static Account acc{get;set;}
    private static User usr{get;set;}
    private static Profile p{get;set;}
    private static List<Event> EventsList{get;set;}
    
    /* Input: The standard type and Activity Type are passed in as parameters.
    Process: Inserts Event records.
    Output: 20 Events are created.
    Changes: 
*/ 
    static void createTestdata(String Eventtype, String MeetingType)
    {
    acc = new Account (name = 'TestUpdateEvents',phone='111111',BillingCity = 'TestUpdateEventsCity', BillingCountry ='TestUpdateEventsCountry', BillingStreet ='TestUpdateEventsStreet', BillingPostalCode ='updateEvent');
    insert acc;
    
    p = [select id from profile where name='Sales Pro'];
    String[] environment = Userinfo.getUserName().split('@');
        
    usr = new User(FirstName ='TestFirstName',Lastname= 'Testlastname',alias = 'Tst',email= 'TestFirstName1.Testlastname1@mpg.com',
               profileid = TestUpdateEvents.p.Id,username= 'TestFirstName'+ 'Testlastname'+'@'+environment[1],emailencodingkey='UTF-8',
               languagelocalekey='en_US',localesidkey='en_US',timezonesidkey='America/Los_Angeles',
                            Country ='USA',
               CompanyName = 'Manpower',Brand__c = 'ManpowerGroup',Region__c = 'Corporate',Sub_Region__c = 'Corporate');
    insert usr;
    
    EventsList = new List<Event>();
        for(Integer i = 0; i < 20;i++)
        {
        Event e = new Event();
        e.OwnerId = usr.Id;
        e.WhatId = acc.Id;
        e.Type = Eventtype;
        e.Meeting_Type__c = MeetingType;
        e.Subject='Test'+i;
       // t.Status = 'Not Started' ;
      //  t.Priority = 'Normal' ;
        e.ActivityDate = Date.today() + 10;
        e.StartDateTime = Date.today() ;
        e.endDateTime = Date.today();
        EventsList.add(e);
        }
   insert EventsList;
   }
    /* Input: No input variables
    Process: Insert Event records whose Type is null and Activity_Type is 'Call'
    Output: Validate the type field. It should be updated to Call
    Changes: None
*/
    static testMethod void MeetingTypeNOTNullAndTypeIsNull() 
    {
        createTestdata(null,'Call');
        
        List<Event> insertedEvents = [SELECT Id,Meeting_Type__c,Type FROM Event WHERE Id in: EventsList ORDER BY Id];
        for(Integer i = 0;i< insertedEvents.size(); i ++)
        {
        System.assertEquals('Call', insertedEvents[i].Type);
        System.assertEquals('Call', insertedEvents[i].Meeting_Type__c);
        }
    }
     /* Input: No input variables
    Process: Insert Event records whose Type is 'Other' and Activity_Type is 'Call'
    Output: Validate the type field. It should be updated to Call
    Changes: None
*/
    static testMethod void MeetingTypeNOTNullAndTypeNOTNull() 
    {
        createTestdata('Other','Call');
        
        List<Event> insertedEvents = [SELECT Id,Meeting_Type__c,Type FROM Event WHERE Id in: EventsList ORDER BY Id];
        for(Integer i = 0;i< insertedEvents.size(); i ++)
        {
        System.assertEquals('Call', insertedEvents[i].Type);
        System.assertEquals('Call', insertedEvents[i].Meeting_Type__c);
        }
    }
   /* Input: No input variables
    Process: Insert Event records whose Type is 'Sent E-mail' and Activity_Type is 'Call'
    Output: Validate the type and Activity_Type fields. Activity_Type should be updated to Sent E-mail.
    Changes: None
*/  
    static testMethod void MeetingTypeNOTNullAndTypeIsSentEmail() 
    {
        createTestdata('Sent E-mail','Call');
        
        List<Event> insertedEvents = [SELECT Id,Meeting_Type__c,Type FROM Event WHERE Id in: EventsList ORDER BY Id];
        for(Integer i = 0;i< insertedEvents.size(); i ++)
        {
        System.assertEquals('Sent E-mail', insertedEvents[i].Type);
        System.assertEquals('Sent E-mail', insertedEvents[i].Meeting_Type__c);
        }
    }
   
    /* Input: No input variables
    Process: Insert Event records whose Type is 'Sent E-mail' and Activity_Type is 'null'
    Output: Validate the Activity_Type field. It should be updated to Sent E-mail
    Changes: None
*/ 
    static testMethod void MeetingTypeNullAndTypeIsSentEmail() 
    {
        createTestdata('Sent E-mail',null);
        
        List<Event> insertedEvents = [SELECT Id,Meeting_Type__c,Type FROM Event WHERE Id in: EventsList ORDER BY Id];
        for(Integer i = 0;i< insertedEvents.size(); i ++)
        {
        System.assertEquals('Sent E-mail', insertedEvents[i].Type);
        System.assertEquals('Sent E-mail', insertedEvents[i].Meeting_Type__c);
        }
    }
 
  /* Input: No input variables
    Process: Insert Event records whose Type is 'Call' and Activity_Type is 'null'
    Output: Validate the type and Activity_Type fields. They should be updated to Call
    Changes: None
*/   
    static testMethod void MeetingTypeNullAndTypeNOTNull() 
    {
        createTestdata('Call',null);
        
        List<Event> insertedEvents = [SELECT Id,Meeting_Type__c,Type FROM Event WHERE Id in: EventsList ORDER BY Id];
        for(Integer i = 0;i< insertedEvents.size(); i ++)
        {
        System.assertEquals('Call', insertedEvents[i].Type);
        System.assertEquals('Call', insertedEvents[i].Meeting_Type__c);
        }
    }
    
    /* Input: No input variables
    Process: Insert Event records whose Type is 'null' and Activity_Type is 'Call'.
    Then update the activity_Type from 'Call' to 'RFI'
    Output: Validate the type and Activity_Type fields. They should be updated to RFI.
    Changes: None
*/ 
    static testMethod void modifyOnlyMeetingType() 
    {
        createTestdata(null,'Call');
        List<Event> updateEvents = new List<Event>();
        
        updateEvents = [SELECT Id,Meeting_Type__c,Type FROM Event WHERE Id in: EventsList ORDER BY Id];
        for(Integer i = 0;i< updateEvents.size(); i ++)
        {
        updateEvents[i].Meeting_Type__c = 'RFI';
        }
        update updateEvents;
        
        List<Event> updatedEvents = [SELECT Id,Meeting_Type__c,Type FROM Event WHERE Id in: updateEvents ORDER BY Id];
        
        for(Integer i = 0;i< updatedEvents.size(); i ++)
        {
        System.assertEquals('RFI', updatedEvents[i].Type);
        System.assertEquals('RFI', updatedEvents[i].Meeting_Type__c);
        }
    }
    /* Input: No input variables
    Process: Insert Event records whose Type is 'null' and Activity_Type is 'Call'.
    Then update the activity_Type to 'Sent E-mail' and Type to 'Other'
    Output: Validate the type and Activity_Type fields. They should be updated to Sent E-mail.
    Changes: None
*/   
    static testMethod void modifyMeetingTypeAndEventType() 
    {
        createTestdata(null,'Call');
        List<Event> updateEvents = new List<Event>();
        
        updateEvents = [SELECT Id,Meeting_Type__c,Type FROM Event WHERE Id in: EventsList ORDER BY Id];
        for(Integer i = 0;i< updateEvents.size(); i ++)
        {
        updateEvents[i].Meeting_Type__c = 'Sent E-mail';
        updateEvents[i].Type = 'Other';
        }
        update updateEvents;
        
        List<Event> updatedEvents = [SELECT Id,Meeting_Type__c,Type FROM Event WHERE Id in: updateEvents ORDER BY Id];
        
        for(Integer i = 0;i< updatedEvents.size(); i ++)
        {
        System.assertEquals('Sent E-mail', updatedEvents[i].Type);
        System.assertEquals('Sent E-mail', updatedEvents[i].Meeting_Type__c);
        }
    }
    /* Input: No input variables
    Process: Insert Event records whose Type is 'null' and Activity_Type is 'Call'.
    Then update the standard Type to 'Sent E-mail' 
    Output: Validate the type and Activity_Type fields. They should be updated to Sent E-mail.
    Changes: None
*/  
    static testMethod void modifyOnlyEventType() 
    {
        createTestdata(null,'Call');
        List<Event> updateEvents = new List<Event>();
        
        updateEvents = [SELECT Id,Meeting_Type__c,Type FROM Event WHERE Id in: EventsList ORDER BY Id];
        for(Integer i = 0;i< updateEvents.size(); i ++)
        updateEvents[i].Type = 'Sent E-mail';
       
        update updateEvents;
        
        List<Event> updatedEvents = [SELECT Id,Meeting_Type__c,Type FROM Event WHERE Id in: updateEvents ORDER BY Id];
        
        for(Integer i = 0;i< updatedEvents.size(); i ++)
        {
        System.assertEquals('Sent E-mail', updatedEvents[i].Type);
        System.assertEquals('Sent E-mail', updatedEvents[i].Meeting_Type__c);
        }
    }
   }

Same code in prod and sandbox since 2012 and not modifed since then.Here are the errors i get in production

System.QueryException: List has no rows for assignment to SObject  (Same error For all the below methods)

Class.TestUpdateEvents.createTestdata: line 27, column 1
Class.TestUpdateEvents.MeetingTypeNOTNullAndTypeNOTNull: line 79, column 1

Class.TestUpdateEvents.createTestdata: line 27, column 1
Class.TestUpdateEvents.MeetingTypeNullAndTypeIsSentEmail: line 112, column 1

Class.TestUpdateEvents.createTestdata: line 27, column 1
Class.TestUpdateEvents.MeetingTypeNullAndTypeNOTNull: line 129, column 1

Class.TestUpdateEvents.createTestdata: line 27, column 1
Class.TestUpdateEvents.modifyMeetingTypeAndEventType: line 173, column 1

Class.TestUpdateEvents.createTestdata: line 27, column 1
Class.TestUpdateEvents.modifyOnlyEventType: line 200, column 1

Class.TestUpdateEvents.createTestdata: line 27, column 1
Class.TestUpdateEvents.modifyOnlyMeetingType: line 147, column 1

Class.TestUpdateEvents.createTestdata: line 27, column 1
Class.TestUpdateEvents.MeetingTypeNOTNullAndTypeIsNull: line 63, column 1

Class.TestUpdateEvents.createTestdata: line 27, column 1
Class.TestUpdateEvents.MeetingTypeNOTNullAndTypeIsSentEmail: line 95, column 1

 
Best Answer chosen by goutham.tatineni1.3893010493585044E12
Andries.NeyensAndries.Neyens
Are you sure the profile Sales Pro still exists ?

All Answers

Andries.NeyensAndries.Neyens
Are you sure the profile Sales Pro still exists ?
This was selected as the best answer
goutham.tatineni1.3893010493585044E12goutham.tatineni1.3893010493585044E12
@andries 

Awesome , Thanks for the help one of our new guys have chnaged it and i was not aware and did not think of checking that .