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

Need help with Test Method
First time creating a Apex Class and the Trigger and I'm getting a error message:
Test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required
I have 100% coverage for the Apex Class but can't find any information on getting Apex Trigger Coverage.
Any help is appreciated
Class:
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);
accountsToUpdate.add(acc);
}
else { Account acc = new Account(Id=c.AccountId,eCon_Completed__c=FALSE);
accountsToUpdate.add(acc);
}
}
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};
AddeCon(con);
// 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);
}
}
Trigger:
trigger ContractUpdate on Contract (after update) {
ContractUpdate.AddeCon(Trigger.new);
}
Message Edited by DT Developer on 09-16-2008 02:32 PM
Message Edited by DT Developer on 09-16-2008 02:43 PM
Test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required
I have 100% coverage for the Apex Class but can't find any information on getting Apex Trigger Coverage.
Any help is appreciated
Class:
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);
accountsToUpdate.add(acc);
}
else { Account acc = new Account(Id=c.AccountId,eCon_Completed__c=FALSE);
accountsToUpdate.add(acc);
}
}
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};
AddeCon(con);
// 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);
}
}
Trigger:
trigger ContractUpdate on Contract (after update) {
ContractUpdate.AddeCon(Trigger.new);
}
Message Edited by DT Developer on 09-16-2008 02:32 PM
Message Edited by DT Developer on 09-16-2008 02:43 PM
to an update call:
Your trigger is an "After Update" one, so the above call should execute it.