You need to sign in to do that
Don't have an account?
Ana 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() ;
}
}
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() ;
}
}
Otherwise you can opt for modifying the test class in such a way that it crosses the validation rule
All Answers
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
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
else you can edit your test class in a way it passses the validation rule
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!!
Otherwise you can opt for modifying the test class in such a way that it crosses the validation rule
We modified a test class and deactivated the validation rule and it worked :)