You need to sign in to do that
Don't have an account?
Need help creating a test class for a trigger.
So...I created a simple trigger to Update a custom Lead field. I need help creating a test class for my trigger...someone please help.
With thanks in advance.
Robert
Here's the trigger:
trigger Update_NetNewLead_Trigger on Lead (before insert) {
// Step 1 - Iterate over incoming Leads and store email in a set
List<String> leadEmails = new List<String>();
for(Lead lead:Trigger.new){
leadEmails.add(lead.Email);
}
// Step 2 - Check whether there are any existing Business Contacts with matching email
List<Contact> contacts = [
SELECT
Id, Email
FROM
Contact
WHERE
Email IN :leadEmails and RecordTypeId='0121A0000007rgsQAA'
// Only Select "Business Contacts"
];
Set<String> contactEmails = new Set<String>();
for(Contact contact:contacts){
contactEmails.add(contact.Email);
}
// Step 3 - Iterate over Leads if Business Contact has matching email set NetNewLead = False
for(Lead lead:Trigger.new){
if(contactEmails.contains(lead.Email)){
lead.NetNewLead__c = False;
}
}
}
Test class
All Answers
Test class