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
DT DeveloperDT Developer 

Test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required

Having issues deloying this Trigger.  The Apex class has 100% coverage but Eclipse requires at least 1% test coverage for the Trigger.  Please help.

trigger ContractTriggerUpdate on Contract (after update) {




public class ContractUpdate {

public static void AddeCon(Contract [] UpdateContract) {

List<Account> accountsToUpdate = new List<Account>();

for(Contract c: UpdateContract)


if ((c.Stage__c=='Completed') && (c.RecordTypeId == '0123000000002Hr') && (c.Status == 'Active')){

Account acc = new Account(Id=c.AccountId,eCon_Completed__c=TRUE);



else { Account acc = new Account(Id=c.AccountId,eCon_Completed__c=FALSE);




update accountsToUpdate;



public static testMethod void test_AddeCon(){

Account test1 = new Account(Name = 'one', eCon_Completed__c=FALSE);

Account test2 = new Account(Name = 'two',eCon_Completed__c=TRUE);

Account test3 = new Account(Name = 'three',eCon_Completed__c=FALSE);

Account test4 = new Account(Name = 'four',eCon_Completed__c=TRUE);

Account[] accts = new Account[] { test1, test2, test3, test4 };

insert accts;

Contract TestCon1 = new Contract (AccountId = test1.Id, Stage__c = 'Completed',Status = 'Active',RecordTypeId = '0123000000002Hr');

Contract TestCon2 = new Contract (AccountId = test2.Id, Stage__c = 'Install on Hold', Status = 'Active');

Contract TestCon3 = new Contract (AccountId = test3.Id, Stage__c = 'Completed', Status = 'Cancelled', RecordTypeId = '0123000000002Hr');

Contract TestCon4 = new Contract (AccountId = test4.Id, Stage__c = 'Completed',Status = 'Active', RecordTypeId = '0123000000002Hr');

Contract[] con = new Contract[] {TestCon1, TestCon2, TestCon3, TestCon4};


// Execute trigger with test data set

// Confirm results

Account[] acctQuery = [SELECT eCon_Completed__c FROM Account WHERE Id = :accts[0].Id OR Id = :accts[1].Id OR Id = :accts[2].Id OR Id = :accts[3].Id];

System.assertEquals(TRUE, acctQuery[0].eCon_Completed__c);

System.assertEquals(FALSE, acctQuery[1].eCon_Completed__c);

System.assertEquals(FALSE, acctQuery[2].eCon_Completed__c);

System.assertEquals(TRUE, acctQuery[3].eCon_Completed__c);




Thanks in advance


 In your test method just create one contract and update that contract, which will invoke the contract trigger, so you can happily migrate it to production.

And one more suggestion, don't hard code Ids or record ids in test methods, it will upload here, but once you are installing in production you may end up with problems.

All the best.

Account[] acctQuery = [SELECT eCon_Completed__c FROM Account WHERE Id = :accts[0].Id OR Id = :accts[1].Id OR Id = :accts[2].Id OR Id = :accts[3].Id];


you can direction write

Account[] acctQuery = [SELECT eCon_Completed__c FROM Account WHERE Id = :accts];



Account[] acctQuery = [SELECT eCon_Completed__c FROM Account WHERE Id in :accts]