+ Start a Discussion
angusgrantangusgrant 

writing a test method for a web form vf/apex

Hi I have created a vf web form(s) with a apex contoller extension that containes fairly sophisticated de-duplication logic. I have written test method(s) that cover all the code required too deploy. These test methods however only test the submission of 1 applicant at a time.

 

I have become increasingly nervous  that once there are allot of submissions in the system some of this deduplication logic may cause the web formto fall over. I therefore have tried to rewite my test method inserting a number of contacts in the system. However if i try and add more than 100 contacts I get the following error:

 

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, ContactDuplicateTrigger: execution of BeforeInsert caused by: System.Exception: Too many SOQL queries: 101 Trigger.ContactDuplicateTrigger: line 9, column 26: []

 

I thought that i had made this trigger bulk safe any help appreciated.

 

 

trigger ContactDuplicateTrigger on Contact (before insert) { Set<string> emailSet = new Set<string>(); for (Contact c : trigger.new){ emailSet.add(c.email); } Contact[] contacts = [select id from Contact where email in : emailSet]; if (contacts.size() > 0) { for(contact c:trigger.new){ c.email.addError('Contact cannot be created - Contact already exists'); } }

 

  ta Angus

 

 

 

srisomsrisom
Should your for loop at the bottom be going through 'contracts' rather than the triggered set ?