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
Ana Maria NaranjoAna Maria Naranjo 

Problem to deploy a trigger in production

Dear all,
We are trying to deploy in production a trigger that capitalize the first letter of a name and a last name of a contact (even when there is a compound given name) and that the last name is in capital letters (example: Jean-Pierre DEBOIS). We tested in Sandbox and everything worked. But when we tried to deploy in production, we get the following errors and the test class has 0% code coverage (please see image below). Could anyone please help us to resolve this problem? 
Thank you! 

Trigger that we are trying to implement: 
trigger CapitalizeName on Contact( before insert , before update)
{
for(Contact c : Trigger.new)
{
if(c.FirstName != null)
{
String prev='';
String response='';
for (Integer i=0;i<c.FirstName.length();i++)
{
String cur=c.FirstName.subString(i ,i+1);
if (prev=='' || prev==' ' || prev=='-')
response+=cur.toUpperCase();
else
response+=cur.toLowerCase();
prev=cur;
}
c.FirstName = response;
}
c.LastName = c.LastName.ToUpperCase() ;
}
}


User-added image

 
Best Answer chosen by Ana Maria Naranjo
jane1234jane1234
YES, you have to  deactivate all validations causing error . Using validations rules of objects which you are inserting by a test class is only need to deactivate .
Otherwise you can opt for modifying the test class in such a way that it crosses the validation rule

All Answers

Ana Maria NaranjoAna Maria Naranjo

The images are not very good, here are the errors that we get: 

AP06Opportunity_TEST
testDeleteOpportunityWon
System.AssertException: Assertion Failed 
Stack Trace: Class.AP06Opportunity_TEST.testDeleteOpportunityWon: line 98, column 1

AP08OpportunityLineItem_TEST
testDeletePackElementsAfterDeletePack
System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Il n'y a pas de planification pour ce produit.: [] 
Stack Trace: Class.AP08OpportunityLineItem_TEST.testDeletePackElementsAfterDeletePack: line 334, column 1

AP08OpportunityLineItem_TEST
testInsertBadQuantity
System.AssertException: Assertion Failed 
Stack Trace: Class.AP08OpportunityLineItem_TEST.testInsertBadQuantity: line 260, column 1

AP08OpportunityLineItem_TEST
testInsertOpportunityLineItemA2ndTime
System.AssertException: Assertion Failed 
Stack Trace: Class.AP08OpportunityLineItem_TEST.testInsertOpportunityLineItemA2ndTime: line 246, column 1

AP08OpportunityLineItem_TEST
testInsertOutOfDate
System.AssertException: Assertion Failed 
Stack Trace: Class.AP08OpportunityLineItem_TEST.testInsertOutOfDate: line 289, column 1

AP08OpportunityLineItem_TEST
testInsertWithBadQuantityDemiJournee
System.AssertException: Assertion Failed 
Stack Trace: Class.AP08OpportunityLineItem_TEST.testInsertWithBadQuantityDemiJournee: line 227, column 1

AP08OpportunityLineItem_TEST
testInsertWithBadStartDate
System.AssertException: Assertion Failed 
Stack Trace: Class.AP08OpportunityLineItem_TEST.testInsertWithBadStartDate: line 303, column 1

AP08OpportunityLineItem_TEST
testInsertWithGoodQuantity
System.AssertException: Assertion Failed 
Stack Trace: Class.AP08OpportunityLineItem_TEST.testInsertWithGoodQuantity: line 181, column 1

AP08OpportunityLineItem_TEST
testInsertWithNoPlanification
System.AssertException: Assertion Failed 
Stack Trace: Class.AP08OpportunityLineItem_TEST.testInsertWithNoPlanification: line 317, column 1

AP08OpportunityLineItem_TEST
testUpdateWithGoodQuantity
System.AssertException: Assertion Failed 
Stack Trace: Class.AP08OpportunityLineItem_TEST.testUpdateWithGoodQuantity: line 197, column 1

AP08OpportunityLineItem_TEST
testUpdateWithGoodQuantityDemiJournee
System.AssertException: Assertion Failed 
Stack Trace: Class.AP08OpportunityLineItem_TEST.testUpdateWithGoodQuantityDemiJournee: line 213, column 1

VFC11MediaPlanning_TEST
testInitController
System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Il n'y a pas de planification pour ce produit.: [] 
Stack Trace: Class.VFC11MediaPlanning_TEST: line 119, column 1

VFC11MediaPlanning_TEST
testSearch
System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Il n'y a pas de planification pour ce produit.: [] 
Stack Trace: Class.VFC11MediaPlanning_TEST: line 119, column 1

VFC11MediaPlanning_TEST
testSearchAM
System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Il n'y a pas de planification pour ce produit.: [] 
Stack Trace: Class.VFC11MediaPlanning_TEST: line 119, column 1

VFC11MediaPlanning_TEST
testSearchWithFamily
System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Il n'y a pas de planification pour ce produit.: [] 
Stack Trace: Class.VFC11MediaPlanning_TEST: line 119, column 1

Gustavo BertolinoGustavo Bertolino
Is there any validation rule active in production that is related to the field that you're changing? The error messages in the print suggests it, I guess. Take a look at validation rules in Prod concerning Contacts and check if they're not interfering it.
Ana Maria NaranjoAna Maria Naranjo
Hi Gustavo, 
Thank you for your answer! 
In fact, there is one validation rule for contacts, and it is to make mandatory the fields civility, name and last name. Should we deactivate the validation rule to deploy the trigger? 
Thank you
jane1234jane1234
yes try deactiating the validation rules . dont forget to set it active back
else you can edit your test class in a way it passses the validation rule
Ana Maria NaranjoAna Maria Naranjo
Thank you both! i will try!
 
Ana Maria NaranjoAna Maria Naranjo
Dear Gustavo and Seethal,
We deactivated the validation rule for contacts, however, we keep having the same errors. There are other validations rules for other objects (such as opportunities), can this affect my test? should we deactivate all the validations rules? sorry for this basic question but i found weird to deactivate all validation rules for other objects that are not affected by the field we are modifying with the trigger. :(
Thank you!!
jane1234jane1234
YES, you have to  deactivate all validations causing error . Using validations rules of objects which you are inserting by a test class is only need to deactivate .
Otherwise you can opt for modifying the test class in such a way that it crosses the validation rule
This was selected as the best answer
Ana Maria NaranjoAna Maria Naranjo
Thank you Seethal! 
We modified a test class and deactivated the validation rule and it worked :)