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
srikanth challasrikanth 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)
 
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.
Best Answer chosen by srikanth challa
Shaijan ThomasShaijan Thomas
When you insert Service Order line, your trigger is correct its works fine. But you may have trigger from package too. Or any other trigger from the same object may hit the package code. May be any parameter missing or anything. you have to contact the package team to resolve this.
Shaijan

All Answers

KevinPKevinP
3 things to note:
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 ThomasShaijan Thomas
When you insert Service Order line, your trigger is correct its works fine. But you may have trigger from package too. Or any other trigger from the same object may hit the package code. May be any parameter missing or anything. you have to contact the package team to resolve this.
Shaijan
This was selected as the best answer