You need to sign in to do that
Don't have an account?

Trigger causing inbound change set issues
I recently deployed a trigger to require rejection comments on an approval process along with the test class. I didn't have any issues in sandbox and received 100% code coverage, but after deploying succesfully to production inbound change sets will sometimes fail and generate the trigger error. Any help is greatly appreciated. I'm not sure what I'm missing.
System.DmlException: Process failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Select the back button and provide a rejection reason comment.: [] Stack Trace: Class.RequireRejectionCommentTestClass.testRejectionWithComment: line 65, column 1
trigger RequireRejectionComment on License_Request__c (before update) { Map<Id, License_Request__c> rejectedRequests = new Map<Id, License_Request__c>{}; for(License_Request__c lic: trigger.new) { License_Request__c oldLic = System.Trigger.oldMap.get(lic.Id); if (oldLic.Approval_Status__c != 'Rejected' && lic.Approval_Status__c == 'Rejected') { rejectedRequests.put(lic.Id, lic); } } if (!rejectedRequests.isEmpty()) { List<Id> processInstanceIds = new List<Id>{}; for (License_Request__c lics : [SELECT (SELECT ID FROM ProcessInstances ORDER BY CreatedDate DESC LIMIT 1) FROM License_Request__c WHERE ID IN :rejectedRequests.keySet()]) { processInstanceIds.add(lics.ProcessInstances[0].Id); } // Now that we have the most recent process instances, we can check // the most recent process steps for comments. for (ProcessInstance pi : [SELECT TargetObjectId, (SELECT Id, StepStatus, Comments FROM Steps ORDER BY CreatedDate DESC LIMIT 1 ) FROM ProcessInstance WHERE Id IN :processInstanceIds ORDER BY CreatedDate DESC]) { if ((pi.Steps[0].Comments == null || pi.Steps[0].Comments.trim().length() == 0)) { rejectedRequests.get(pi.TargetObjectId).addError( 'Select the back button and provide a rejection reason comment.'); } } } }
Are you pushing all the test classes at the same time? Is it 100% code coverage in both Production and Sandbox?

Can you include code from your test class RequireRejectionCommentTestClass?

Yes, I have gotten 100 % code coverage in production and sandbox. Here is my test class:

You have a validation rule in production that is not in sandbox preventing either License_Type__c or Cost_Center__c record to be inserted without a "rejection reason comment" (as you errored in the validation). Either add this rejection reason comment to your test class record before insert/update, remove the production validation or write an exception to your production validation for !$User.Alias != 'DeploymentUserAlias'.