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
JayDP123JayDP123 

Apex Trigger Deployment issue with Test Classes

Hello,

 

I have an Apex Trigger that I am trying to deploy through Change Sets from Sandbox to Production. It is a field update on the opportunity object. It works fine in Sandbox, and when I run tests I get 100% test coverage. However when I try to "validate" in the inbound change sets section in production I get errors like this: 

quoteExtTests.basicAttachTest()Class109 Failure Message: "System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, JP_Opportunity: execution of BeforeInsert caused by: System.QueryException: List has no rows for assignment to SObject Trigger.JP_Opportunity: line 10, column 1", Failure Stack Trace: "Class.quoteE...
quoteExtTests.basicSaveTest()Class109 Failure Message: "System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, JP_Opportunity: execution of BeforeInsert caused by: System.QueryException: List has no rows for assignment to SObject Trigger.JP_Opportunity: line 10, column 1", Failure Stack Trace: "Class.quoteE...

 

These Classes are from years ago, not even sure that they're still in use. I am new to deploying apex and not sure what they mean? Can someone help explain is this something to be concerned about? Can I ignore the test classes? Is it my code that is causing the issue? My code is below: 

 

trigger SF_Opportunity on Opportunity (before insert, before update) {
    
    //Change the Opportunity_Manager__c so the field is up to date with the current Opportunity Owner's Manager. 
    for (opportunity o : Trigger.new) {
        //get a list of the user object from the opportunity owner. 
        List<User> oppOwner = [select managerid, name, UserRole.name from user where user.id =: o.ownerid];
        system.debug('USER LIST ***' + oppOwner);
    for (user oppOwn : oppOwner){
            //update the fields based on the id of the opportunity owner
          o.Opportunity_Owner_Manager__c = [select name from user where user.id =: oppOwn.managerid].name;
          o.Opp_Owner_Role__c = [select name from UserRole where UserRole.id =: oppOwn.UserRoleID].name;
        }
  }
}

 

Thanks for the help, again I am new to this just trying to learn as much as I can.

 

Thanks! 

Alex JaimesAlex Jaimes

Hello JayDP123.

Something similar happend to me as well, after we updated a validation rule in production.

When you deploy and validate your code into the production org, it is not only your new code that is valiadated, but all the dependencies, this is why it takes some time. Your Code might be totally fine. I would suggest deactivating the quoteExtTests.basicAttachTest() and quoteExtTests.basicSaveTest() Class to see if you can deploy your new code, if they are not used anymore.

Vinit_KumarVinit_Kumar

The root cause of this issue is below  SOQL query is returning no rows:-

 

select name from user where user.id =: oppOwn.managerid

 

Please check if the previous List i.e. oppOwner has manager value or not.

 

Sridhar BonagiriSridhar Bonagiri

 

Hi,

 

I think this test method in the test class is checking the data which is already existing the production org and that is the reason for these exceptions. Change the code in the test method in such a way that do not go in to the for loop without checking the list size.

 

Regards,

Sridhar Bonagiri