You need to sign in to do that
Don't have an account?
Shweta 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
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
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
Fix the test class and try deploying again
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
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
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.
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