You need to sign in to do that
Don't have an account?
Test coverage help please, thanks!
Hi everyone
My first trigger in salesforce, is working in sandbox but I'm having a problem with the coverage.
I was already reading about it and couldn't find a solution, can anyone help?
I'm a new at salesforce so any help will be more than welcome.
The code is:
trigger AccountTrigger on Account (before insert) { List<Account> lst_in = trigger.new; for(Account acc:lst_in){ acc.ShippingCity = acc.BillingCity; acc.PersonMailingCity = acc.BillingCity; acc.PersonOtherCity = acc.BillingCity; acc.ShippingStreet = acc.BillingStreet; acc.PersonMailingStreet = acc.BillingStreet; acc.PersonOtherStreet = acc.BillingStreet; acc.ShippingState = acc.BillingStreet; acc.PersonMailingState = acc.BillingState; acc.PersonOtherState = acc.BillingState; acc.ShippingPostalcode = acc.BillingPostalcode; acc.PersonMailingPostalcode = acc.BillingPostalcode; acc.PersonOtherPostalcode = acc.BillingPostalcode; acc.ShippingCountry = acc.BillingCountry; acc.PersonMailingCountry = acc.BillingCountry; acc.PersonOtherCountry = acc.BillingCountry; } }
The errors are:
AccountTrigger
Test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required Deploy Error
Average test coverage across all Apex Classes and Triggers is 66%, at least 75% test coverage is required.
I can understand that I will have to tweak the code to have more than the minimum expected, but how?
Thank you
All Answers
@isTest(SeeAllData=true)
private class TestAccountTrigger{
public static testMethod void TestAccountTrigger(){
Account a=new Account(name='Test Account');
insert a;
}
}
The above test class will help you to cover test code. You cannot deploy a trigger with 0% code coverage.
Hi testrest97
Thanks.
Sorry if I'm looking to be very basic (because I am), but can you give me a step by step indication.
Thank you.
My class
and the trigger
It was looking good, at least for me... but, when cretaing a customer I get this error:
"Error: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, AccountTrigger: execution of BeforeInsert caused by: System.QueryException: List has no rows for assignment to SObject Class.AccountTrigger.updateAccount: line 8, column 1 Trigger.AccountTrigger: line 6, column 1: [] (System Code)"
Any help would be more than welcome.
Thank you
This is a test class and will help you achieve the code coverage.
Regards,
Satish Kumar
Thank you it's solved.