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

How to test Apex Trigger
I am new to Apex and am having an issue moving a trigger I created in Sandbox through a Change Set to production. The trigger I created is working great but when I try the Change Set it does not validate because it says I need to test the trigger. I was reading about Apex Test Methods but am a little confused as to how to I execute the test. Any help on next steps would be greatly appreciated! The trigger I need to test is:
trigger CoverageLetterTask on Claim__c (before update) {
List<Task> tasks = new List<Task>();
for(Claim__c claim : Trigger.new){
if(claim.Task_created__c != null &&
claim.Task_created__c == false &&
claim.Approval_Received__c == true &&
claim.Insured__c != 'Catholic Health East'){
//Do your Task creation
Task CoverageTask= new Task();
CoverageTask.ActivityDate = claim.LVL_Received_Date__c + 30;
CoverageTask.WhatId = claim.id;
CoverageTask.OwnerId = claim.Assigned_Examiner2__c;
CoverageTask.Priority = 'Normal';
CoverageTask.Status = 'Not Started';
CoverageTask.Subject = claim.Program_ID__c + ' Coverage Letter -- ' + claim.Insured__C + ' -- ' + claim.Claimant_Name__c;
//Add the Task
tasks.add(CoverageTask);
//Update the field on Claim so this isn't done again
claim.Task_Created__c = true;
}
}
insert tasks;
}
Hi,
You need to write test class which does the below operation like in your test class with test data you need to perform an insert on the claim__c object.
@isTest
private class TestCoverageLetterTask {
private static testMethod void testCoverageLetterTaskMethod() {
Test.StartTest();
// Here you code to insert in to Claim__c object..
Test.StopTest();
}
}
All Answers
Hi,
You need to write test class which does the below operation like in your test class with test data you need to perform an insert on the claim__c object.
@isTest
private class TestCoverageLetterTask {
private static testMethod void testCoverageLetterTaskMethod() {
Test.StartTest();
// Here you code to insert in to Claim__c object..
Test.StopTest();
}
}
That worked! And I had multiple triggers on the Claim Object and was able to create multiple claim updates in the one class and got 100% Code Coverage! Thanks for your help on this!