I am new to Apex development and I’m starting to work on my project in Apex. I would like to do following:
using an email service //I figured this part
get emailAddress from an email //know how to do this
if there is already exisiting lead or contact with the same emailAddress
update his information
else
create new lead
I would like to kow how I can search my database (saleforce’s leads and contacts) and update existing user’s info.
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.
}
The other option is to execute a search limiting the scope to email fields.
}