• Sean McMickle 10
  • NEWBIE
  • 55 Points
  • Member since 2017

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 10
    Replies
I'm trying to create a new trigger before Lead insertion to check for duplicates from Leads or Contacts and prevent insertion. The duplicate check I'm going for is checking if newLeadEmail = existingEmail or if newLeadEmail = existingAltEmail (etc etc) basically preventing duplicates being added if alt email or email exists anywhere between the email or altEmail fields.

I'm getting a 71% code coverage unfortunately and really don't know how to go about making a test case cover more. I've created a test case that checks over some very basic insertion of Leads but it isn't covering my code.

Here are the lines for Lead checking that are not covered (similar lines for contact checking are also not covered):
*existingLeadList queries the database for existing leads that have Email or Alt Email matches
for(Lead newLead : Trigger.new){
                for(Lead exisitingLead : existingLeadList ){
                    if((newLead.Email == exisitingLead.Email)||(newLead.Alt_Email__c == exisitingLead.Alt_Email__c)||(newLead.Email==exisitingLead.Alt_Email__c)||(newLead.Alt_Email__c == exisitingLead.Email)){
                        newLead.addError('Duplicate Lead');
                    }
                }
            }

Any ideas on how to make a test case for this? Is there something I'm missing? Shouldn't basic Lead insertion test cases work for this?

Also as a side question: when I add the checking for alt email in my test for inserting duplicate leads it fails (naturally) because this trigger isn't in place yet to make it succeed at failing to insert a duplicate based on newEmail = oldAltEmail, but I shouldn't be publishing a test that fails should I? How do I deploy my trigger if the test I create to test it fails unless the trigger is active?

Any help here is appreciated. I'm a bit stuck at the moment. Thanks!
I'm trying to create a new trigger before Lead insertion to check for duplicates from Leads or Contacts and prevent insertion. The duplicate check I'm going for is checking if newLeadEmail = existingEmail or if newLeadEmail = existingAltEmail (etc etc) basically preventing duplicates being added if alt email or email exists anywhere between the email or altEmail fields.

I'm getting a 71% code coverage unfortunately and really don't know how to go about making a test case cover more. I've created a test case that checks over some very basic insertion of Leads but it isn't covering my code.

Here are the lines for Lead checking that are not covered (similar lines for contact checking are also not covered):
*existingLeadList queries the database for existing leads that have Email or Alt Email matches
for(Lead newLead : Trigger.new){
                for(Lead exisitingLead : existingLeadList ){
                    if((newLead.Email == exisitingLead.Email)||(newLead.Alt_Email__c == exisitingLead.Alt_Email__c)||(newLead.Email==exisitingLead.Alt_Email__c)||(newLead.Alt_Email__c == exisitingLead.Email)){
                        newLead.addError('Duplicate Lead');
                    }
                }
            }

Any ideas on how to make a test case for this? Is there something I'm missing? Shouldn't basic Lead insertion test cases work for this?

Also as a side question: when I add the checking for alt email in my test for inserting duplicate leads it fails (naturally) because this trigger isn't in place yet to make it succeed at failing to insert a duplicate based on newEmail = oldAltEmail, but I shouldn't be publishing a test that fails should I? How do I deploy my trigger if the test I create to test it fails unless the trigger is active?

Any help here is appreciated. I'm a bit stuck at the moment. Thanks!
I have one object and 100 users one trigger will be fire. 50 users trigger will be fire and 50 users trigger will not be fire how to achive it ( Through Programing )
Hey everyone-

We are reaching the 100 SOQL query per transaction in our custom Apex object. Is there a work around or way to get our limit increased?
Hi,
I'm trying add in my custom field of type Select List, all the Campaign that I have.
So I want know how do that using apex?

I'm new with apex, and I don't found anything that explain how I insert a value in a field.

Thanks
Rafael