You need to sign in to do that
Don't have an account?

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!!
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.
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?