You need to sign in to do that
Don't have an account?
Losintikfos
1% Coverage
Hi Experts,
I have this trigger;
I also have this apex class which is invoked by the trigger;
I am using this test coverage below;
Unfurtunately i get error;
Test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required
Can anyone help to resolve this?
I have this trigger;
Code:
trigger addParent on Account (before insert, before update) { addParent.addAddress(trigger.new); }
I also have this apex class which is invoked by the trigger;
Code:
public class addParent{ public static void addAddress(Account[] acc) { /**Set Set variables to hold the result as class members**/ String parent; String pCode; parent = acc[0].ParentId; for (Account ac : [select Billing PostalCode where Id = :parent]) { pCode = ac.BillingPostalCode; } acc[0].BillingPostalCode = pCode; } }
I am using this test coverage below;
Code:
public class testAddParentAddress { public static testMethod void testAddParent(){ List<Account> accl = new Account[]{new Account()}; accl[0] = new Account(Name = 'test', ParentId = '001R000000955CDIAY', BillingState = 'MASS', BillingCity = 'Tazmania', BillingCountry = 'AUS', BillingPostalCode = 'MJ 25355', BillingStreet ='St. Kilda'); String pCode = accl[0].BillingPostalCode; String Street= accl[0].BillingStreet; System.assertEquals('MJ 25355', pCode); System.assertEquals('St. Kilda', Street); addParent.addAddress(accl); for (Account o : [select BillingState, BillingCity, BillingCountry, BillingPostalCode, BillingStreet from Account where Name = 'Test']) { o.BillingState= 'UK' ; update o; } } }
Unfurtunately i get error;
Test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required
Can anyone help to resolve this?
To run the trigger you will need to either insert a new record, or update an existing record. In your case, since you created an account called test you will need to use:
Instead of:
In the end i have to use the two to gain total coverage. Did something like this;