We had an offshore team develop us an app, they have installed it in my developer account and now I am trying to make a package for app exchange submission.
I select the app, the apex classes including test classes and the trigger (app only has 1 trigger) and when I attempt to upload the package I get this message back
One or more Apex triggers lack test coverage. Add test coverage for the following triggers and upload again: LeadSurveyDeleteEvent
Here is the LeadSurveyDeleteEvent trigger
trigger LeadSurveyDeleteEvent on Lead (before delete)
{
Map<ID,Lead> old_lead_list = Trigger.oldMap;
Set<ID> ids = old_lead_List.keySet();
delete [Select ID from Survey__c where SurveyLead__c IN :ids];
}
And the test class
@isTest(SeeAllData=true)
public class LeadSurveyDeleteEventTest {
static testMethod void addDeleteLeadTest()
{
String [] arrayOfId = new List<String>();
arrayOfId.Add('12');
arrayOfId.Add('13');
delete [Select ID from Survey__c where SurveyLead__c IN :arrayOfId];
}
}
I am not familiar with Apex code but when I run the test it completes 1/1.
Edit: After your comments on the quality of code I updated it myself:
@isTest(SeeAllData=true)
public class LeadSurveyDeleteEventTest {
static testMethod void testLeadTrigger_Delete()
{
Lead newLead = new Lead();
newLead.Email = '[email protected]';
newLead.Company = 'Test Company Name';
newLead.LastName = 'Smith';
insert newLead;
Survey_Responses__c newSurveyResponse = new Survey_Responses__c();
newSurveyResponse.Survey_Name__c = 'Test survey name1';
newSurveyResponse.Question__c = 'Where do you live?';
newSurveyResponse.Answer__c = 'Canada';
newSurveyResponse.SurveyLead__c = newLead.Id;
insert newSurveyResponse;
Test.startTest();
delete newLead;
Test.stopTest();
Lead tLead = [Select Id, IsDeleted from Lead WHERE Id = :newLead.Id ALL ROWS];
System.assertEquals(tLead.IsDeleted, true);
Survey_Responses__c tSurveyResponse = [Select Id, IsDeleted from Survey_Responses__c WHERE Id = :newSurveyResponse.Id ALL ROWS];
System.assertEquals(tSurveyResponse.IsDeleted, true);
}
}
Can someone shed light on what the ALL ROWS words do? And the startTest/endTest block?