+ Start a Discussion
Shweta SoparkarShweta Soparkar 

Error while deploying a trigger to production

trigger updateProduct on Product2 (after insert, after update) {

if(checkRecursive.runOnce())
{

List <Product2> li= new List<Product2>();
Set <Id> nameId = new Set<Id>();
List <Trademark__c>  trademarkList  = new List<Trademark__c>();

String myTradeMark = 'NotFound';
String myTradeMarkWord = 'NotFound';

    for(Product2 p : Trigger.new)
    {
        //if Name is not null
            nameId.add(p.Id);
            trademarkList   = [select Name, Trademark__c,Trademark_Word__c  FROM Trademark__c];
            
            if(!trademarkList.isEmpty())
            {
                for(Trademark__c t:trademarkList)
                {
                    if((p.Name).contains(t.name)) 
                    {
                    myTradeMark= t.Trademark__c;
                    myTradeMarkWord = t.Trademark_Word__c;
                    }
                }
               
            }
        //if Name is null put "Not Found" for TradeMark and TradeMark word
        else
        {
             myTradeMark= 'NotFound';
             myTradeMarkWord = 'NotFound';  
        }
    }
        li = [select Trade_Mark__c ,Trade_Mark_Word__c FROM Product2 where Id In :nameId];
    
        for(Product2 p :li)
        {
            p.Trade_Mark__c=myTradeMark;
            p.Trade_Mark_Word__c=myTradeMarkWord;
        }
        update li;
     
   } 
}
I am getting the below errors while deploying the trigger to porduction:-


"System.AssertException: Assertion Failed: Expected: 5, Actual: 6  Stack Trace: Class.SObjectUnitOfWorkTest.testUnitOfWorkNewDirtyDelete: line 139, column 1" 

System.AssertException: Assertion Failed: Expected: 5, Actual: 6 
Stack Trace: Class.SObjectUnitOfWorkTest.testUnitOfWorkOverhead: line 237, column 1
Best Answer chosen by Shweta Soparkar
Shweta SoparkarShweta Soparkar
@Rohit:
Thanks for you prompt replies!
I was able to find the solution to it!

My trigger was working fine in the sandbox, but while deploying it to the production it was giving the error because it was running its own test class in production and that test class was failing.

The solution which helped me was that, while deploying it to production I selected the 'Run Specified option' so that it will run only the test case which I was providing and not its own.

Now able to successfully deploy my code.

Thank you all!

Regards,
Shweta 

All Answers

badibadi
The errors are not from the trigger, When you deploy to production, salesforce runs all the test classes in the org. In this case your test class SObjectUnitOfWorkTest is failing.

Fix the test class and try deploying again
Rohit Sharma 66Rohit Sharma 66
Following two methods of your test class "SObjectUnitOfWorkTest" are getting failed in Production:
testUnitOfWorkNewDirtyDelete
testUnitOfWorkOverhead

Run the class in pre prod and try to fix the error, if you are in hurry then just comment out the system.assert() methods from both the methods and deploy to production.
Whenever u deploy any apex code in the production, it will run all the test classs from Production org to make sure you have the test coverage of more than 75%.

Let me know if this helps
Shweta SoparkarShweta Soparkar
@Rohit:

Thanks for replying!
Will the test case run even if I have the test coverage more than 75%?
because my trigger has the coverage of more than 75%. 

Also, I wont be able to change the SObjectUnitOfWorkTest test case as it is the production org test case and I am not able to chane it.

Awaiting your answer
 
Rohit Sharma 66Rohit Sharma 66
All the test class will always run in production, even if you have test coverage of 100% to make sure that with the new code push u still have more than 75% test coverage and no test class is failing. U can consider your existing scenerio, where bcoz of ur trigger 1 test class is getting failed.

Now, if you have test class in production then it will also be available in your pre production. Just modify the test class in pre production and push that to prodution along with your trigger. Once u fix the test class in Pre Prod, just run it once to make sure its working fine and all the methods are passing. Then move that to production.

Please try and let me know if it works.
Shweta SoparkarShweta Soparkar
@Rohit:
Thanks for you prompt replies!
I was able to find the solution to it!

My trigger was working fine in the sandbox, but while deploying it to the production it was giving the error because it was running its own test class in production and that test class was failing.

The solution which helped me was that, while deploying it to production I selected the 'Run Specified option' so that it will run only the test case which I was providing and not its own.

Now able to successfully deploy my code.

Thank you all!

Regards,
Shweta 
This was selected as the best answer