You need to sign in to do that
Don't have an account?
srikanth challa
Apex Test Class Failed But Trigger Got 100% Code Coverage
Hi Guys, I have a trigger to automate the Approval process and I got 100% code coverage when I run my test class even though the test failed due to managed package trigger conflict (System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, SVMXC.WORD_Trigger1: execution of BeforeUpdate)
Can any one help me to pass the test class otherwise I cannot deploy into production.
Trigger : trigger SubmitForApproval on SVMXC__Service_Order_Line__c (after insert) { for (Integer i = 0; i < Trigger.new.size(); i++) { if (Trigger.new[i].RecordTypeId == '012G000000163Ww' ) { // create the new approval request to submit Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest(); req.setComments('Submitted for approval. Please approve.'); req.setObjectId(Trigger.new[i].Id); // submit the approval request for processing Approval.ProcessResult result = Approval.process(req); // display if the reqeust was successful System.debug('Submitted for approval successfully: '+result.isSuccess()); } } } Test Class: @IsTest private class Workdetail { static testmethod void SubmitForApproval(){ test.starttest(); SVMXC__Service_Order_Line__c quote = new SVMXC__Service_Order_Line__c( SVMXC__Service_Order__c='a0oK0000001RPot', RecordTypeId='012G000000163Ww'); SVMXC__Line_Type__c='Labor', insert quote; test.stopTest(); } }
Can any one help me to pass the test class otherwise I cannot deploy into production.
Shaijan
All Answers
1: your setup of the object should exist outside the test.startTest() / test.stopTest() methods.
2: tests are not tests without asserts.
3: if you look through the debug logs, you'll likely find more details to that error message. The details will almost certiantnly point to a field missing it's value or some other kind of valididation failure that is preventing the insert. Look through the logs and post that extended error message for more help
Shaijan