Skip to main content
Hello, I am trying to unlock a "Matter" record when the record goes into an approval process. A trigger will see that it is locked and then unlock the record. This is working, but my test class is only covering 66%. How can I get it to 100%? Thanks!

Trigger

trigger UnlockMatter on litify_pm__Matter__c (after insert, after update) {

for(litify_pm__Matter__c matter : trigger.New) {

If(Approval.isLocked(matter.Id)) {

Approval.unlock(matter.Id);

}

}

}

Test Class

@isTest

public class TestUnlockMatter {

@isTest static void TestEditMatterInApproval() {

// Test data setup

// Create A Party to assign to the matter

Account party = new Account(litify_pm__First_Name__c='Jim', litify_pm__Last_Name__c='Halpert');

insert party;

// Create A Matter that is locked and unlock and edit it

litify_pm__Matter__c matter = new litify_pm__Matter__c(litify_pm__Display_Name__c='Jim Halpert vs. Dwight Schrute', litify_pm__Client__c= party.Id);

insert matter;

Approval.lock(matter.Id);

//Perform Test

Test.startTest();

Approval.unlock(matter.Id);

matter.litify_pm__Display_Name__c ='Jim Halpert vs. Micheal Scott';

Test.stopTest();

}

}

 
2 respuestas
  1. 5 nov 2019, 20:52
    Good Afternoon Jacob,

    Hope that your day is off to an amazing start. Can we request for you to try the new updated test class below and report how it works for you? Thank you, and hope this helps. May God bless you abundantly.

    @isTest

    public class TestUnlockMatter {

    @isTest static void TestEditMatterInApproval() {

    // Test data setup

    // Create A Party to assign to the matter

    Account party = new Account(litify_pm__First_Name__c='Jim', litify_pm__Last_Name__c='Halpert');

    insert party;

    // Create A Matter that is locked and unlock and edit it

    litify_pm__Matter__c matter = new litify_pm__Matter__c(litify_pm__Display_Name__c='Jim Halpert vs. Dwight Schrute', litify_pm__Client__c= party.Id);

    insert matter;

    //Perform Test

    Test.startTest();

    //Lock record and update to activate trigger

    Approval.lock(matter.Id);

    matter.litify_pm__Display_Name__c ='Jim Halpert vs. Micheal Scott';

    update matter;

    Test.stopTest();

    }

    }

    Best Regards,

    Anthony McDougald
0/9000