You should execute a query on lead and contact using the email address as the criteria for you query. If it returns 0 records for the Lead and 0 records for the Contact, then you would create a new Lead Your query could return more than 1 record for either Lead or Contact, so you will have to develop a strategy to handle that case. Email address is not required to be unique public class StackOverflowExample { public static void test(String email) { handleNewEmail(email); } private static void handleNewEmail(String email) { List leads = select id, email from Lead where email = :email; List contacts = select id, email from Contact where email = :email; if (leads.size() == 0 && contacts.size() == 0) { //Create new lead insert new Lead(Company = 'Lead Company', FirstName = 'firstname', LastName = 'lastname', Email = email); } else if (leads.size() == 1) { // Update this lead leads0.
FirstName = 'newfirstname'; update leads; } else if (contacts.size() == 1) { // Update this contact contacts0. FirstName = 'newfirstname'; update contacts; } else { // Must be more than 1 contact or lead System. Debug('\nMore than 1 contact or lead.'); } } } The other option is to execute a search limiting the scope to email fields public class StackOverflowExample { public static void test(String email) { handleNewEmail(email); } private static void handleNewEmail(String email) { List> searchResults = FIND :email IN Email Fields RETURNING Lead(Id, FirstName, LastName), Contact(Id, FirstName, LastName); List leads = ((List)searchResults0); List contacts = ((List)searchResults1); if (leads.size() == 0 && contacts.size() == 0) { //Create new lead insert new Lead(Company = 'Lead Company', FirstName = 'firstname', LastName = 'lastname', Email = email); } else if (leads.size() == 1) { // Update this lead leads0.
FirstName = 'newfirstname'; update leads; } else if (contacts.size() == 1) { // Update this contact contacts0. FirstName = 'newfirstname'; update contacts; } else { // Must be more than 1 contact or lead System. Debug('\nMore than 1 contact or lead.
'); } } }.
You should execute a query on lead and contact using the email address as the criteria for you query. If it returns 0 records for the Lead and 0 records for the Contact, then you would create a new Lead. Your query could return more than 1 record for either Lead or Contact, so you will have to develop a strategy to handle that case.
Email address is not required to be unique. Public class StackOverflowExample { public static void test(String email) { handleNewEmail(email); } private static void handleNewEmail(String email) { List leads = select id, email from Lead where email = :email; List contacts = select id, email from Contact where email = :email; if (leads.size() == 0 && contacts.size() == 0) { //Create new lead insert new Lead(Company = 'Lead Company', FirstName = 'firstname', LastName = 'lastname', Email = email); } else if (leads.size() == 1) { // Update this lead leads0. FirstName = 'newfirstname'; update leads; } else if (contacts.size() == 1) { // Update this contact contacts0.
FirstName = 'newfirstname'; update contacts; } else { // Must be more than 1 contact or lead System. Debug('\nMore than 1 contact or lead. '); } } } The other option is to execute a search limiting the scope to email fields.
Public class StackOverflowExample { public static void test(String email) { handleNewEmail(email); } private static void handleNewEmail(String email) { List> searchResults = FIND :email IN Email Fields RETURNING Lead(Id, FirstName, LastName), Contact(Id, FirstName, LastName); List leads = ((List)searchResults0); List contacts = ((List)searchResults1); if (leads.size() == 0 && contacts.size() == 0) { //Create new lead insert new Lead(Company = 'Lead Company', FirstName = 'firstname', LastName = 'lastname', Email = email); } else if (leads.size() == 1) { // Update this lead leads0. FirstName = 'newfirstname'; update leads; } else if (contacts.size() == 1) { // Update this contact contacts0. FirstName = 'newfirstname'; update contacts; } else { // Must be more than 1 contact or lead System.
Debug('\nMore than 1 contact or lead. '); } } }.
In the Salesforce built-in help you can find some info about the InboundEmail object. The page contains also 2 examples about working with Contacts and Leads based on email address extracted from the message.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.