+ Start a Discussion

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 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.');
// 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

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


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.


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:

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