here's a brief rundown of the trigger I'm trying to test:
- this trigger is trying to put a cap on records with a certain lead source. If someone selects this source and tries to save the record, it generates an error and tells them that they've hit the cap.
- the trigger works in the sandbox as advertised
So here's the code for the trigger:
trigger ProtectedCap on Lead (before update) {
List<Lead> protectedTotal = [SELECT Owner_ID__c FROM Lead WHERE Status = 'Protected'];
for (Lead myLead : Trigger.new) {
if (myLead.Status == 'Protected' && protectedTotal.size() >= 100) {
String protectedError = 'Protected Leads are at 100, please remove leads from Protected status to add.';
myLead.addError (protectedError);
}
}
}
For the test class, I generated leads and assigned the lead status that I'm trying to cap. It runs and hits the error when it's supposed to, but of course the test thinks it's a bad error and fails out. To be honest there's probably a number of other things wrong with it but I don't know enough to know enough. Ya know?
Here's the test class:
@isTest
private class testNewLeadCap {
static testMethod void validateNewLeadCap()
{
List<Lead> leads = new List<Lead>{};
for(Integer i = 0; i <200; i++){
Lead a = new Lead(FirstName = 'Test' + i, LastName = 'Testies' + i, Status = 'Protected');
leads.add(a);
}
test.startTest();
insert leads;
test.stopTest();
}
}
Any assistance/insight would be greatly appreciated!
Cheers!