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
dblazedblaze 

Trigger Code Coverage

Hi Everyone,

As of right now I have a trigger that works exactly how I want it too but I am not able to get the test coverage working so that I can push it to production.  Can anyone help?  Below is the code for my trigger and my test coverage as it stands now...

 

Trigger

trigger AssignmentSubmitForApproval on lmscons__Transcript_Line__c (after update) {

for (Integer i = 0; i < Trigger.new.size(); i++) {

if (Trigger.old[i].lmscons__Percent_Complete__c == 0 && Trigger.new[i].lmscons__Percent_Complete__c == 100) {

// 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 Coverage

@isTest
private class TestAssignmentSubmitForApproval {

static testMethod void MyUnitTest() {
lmscons__Transcript_Line__c lms = new lmscons__Transcript_Line__c();

lms.lmscons__Percent_Complete__c = 0;
//lms.lmscons__Transcript__c = lms.Id;
//lms.lmscons__Training_User_License__c = lms.id;

// insert the new lms
insert lms;
// change the probability of the lms so the trigger submits it for approval
lms.lmscons__Percent_Complete__c = 100;
// update the lms which should submit it for approval
update lms;
}
}

 

Note: the Transcript and User Liscensce fields are Master-Detail

 

Any help would be greatly appreciated!!

 

Rahul SharmaRahul Sharma

Hey,

Have you filled all the required fields of lmscons__Percent_Complete__c in you test class?

Also would like to know what is the problem you are facing with test class and hows much does it covered.

dblazedblaze

Hi Rahul,

This is the error I am receiving:

 

System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [lmscons__Transcript__c, lmscons__Training_User_License__c]: [lmscons__Transcript__c, lmscons__Training_User_License__c]

 

The test coverage is at 0%, I am having trouble setting up the fake data that is required for me to actually test with, any ideas?

Rahul SharmaRahul Sharma
dblaze, Error states that you need to fill all the required fields in records of your test class before performing insert/update operation.
You need to fill the fields which are required:
lms.lmscons__Transcript__c
lms.lmscons__Training_User_License__c

 If they are master detail fields, create a master record first and then use its id in reference field of child record.