+ Start a Discussion
Domnic JohnsonDomnic Johnson 

Create a account field on leads record

Hi All, 

I want to check if there is a way, I could create a custom field on lead object called "Account" and this field populates ever time a new leads comes in to salesforce, the Account field should populate a associated existing account based on matching email criteria. 

Thanks
Guru Vemuru 1Guru Vemuru 1
Hi Johnson ,
can you explain where you want to populate.
As per my understandind based on question use Lead Auto Response Rule. Mention criteria in that,it will send notification.

If it is not that requirement Please let me know.
Domnic JohnsonDomnic Johnson
Hi Vemuru, 

I wanted to create a new custome field on Lead Object.

So the requirement is:
  • New lead comes in and the email address is xyz@gmail.com
  • Custome field needs to search for a account  which has the same email id (xyz@gmail.com) In Account object and if it find a acount with the same email, populate  the new custome field with that account link
Hope I made it clearn this time. Please, let me know if its still confusing.


 
JohnHernandez.ax1746JohnHernandez.ax1746
Hi Domnic,
You can create a trigger with something like
String emailFromLead = lead.email;
List<contact> contactList = [Select accountid from contact where email=:emailFromLead];
if (contactList.size() > 0){
    lead.Account__c = contactList[0].AccountId;
}
Of course, it would need to be bulkified and follow best practices, but that is the general idea.

Regards,

John

 
Guru Vemuru 1Guru Vemuru 1
Hi Johnson,
     Yes you can create a trigger that checks  Lead-email with account and fetch that account record  in Lead custom field .

You have to do sothing like this :

1. Create lookup field in Lead.
2.Create Trigger  fetch the account record when {!Lead.Email}=={!Account.email}

I hope it will help you if not please let me know.
HARSHIL PARIKH AKA:GovindHARSHIL PARIKH AKA:Govind
Hello Domnic,
Try using the following trigger,
 
Trigger JoinLeadToAccount On Lead(Before Insert, Before Update, AFter UnDelete){
     If(Trigger.IsInsert || Trigger.IsUpdate || Trigger.IsUnDelete){
         For(Lead Ld : Trigger.New){
             If(Ld.Email != Null && Ld.Account__c == null)
             {
                 List<Account> fetchingSimilarAct = [Select Id, Email__c FROM Account WHERE Email__c = :Ld.Email LIMIT 1];
                 
                 If(!fetchingSimilarAct.IsEmpty())
                 {
                     Ld.Account__c = fetchingSimilarAct[0].Id;
                 }          
             }
         }
     }
}

I am assuming you have Email__c as a custom field on an Account object and Account__c custom field on Lead object.
What this trigger does it whenever you enter the lead and if the lead has an email and there is no Account attached to it yet then it will go and find an account for it based on the similar email address.
If you enter a Lead with the email and you have already provided an account for it then the trigger won't override that account. Trigger works only for the Leads who has email address and who has their account field blank and also whoes email matches with the one o the Account's email in database.

Hope this helps & if it solves the query then please mark it as best answer. Thank you!
Domnic JohnsonDomnic Johnson
Hi All, 
Thank for responding back.

I'm new to this, so not able to make the best use of your suggestions.

Govind, The Email field on Account is a Standard field. and we get all our leads from the web. your solution would work perfectly but then, the Email field on account is Standard and not custom.

 
JohnHernandez.ax1746JohnHernandez.ax1746
Domnic,

Email is NOT a standard field on the Account object.  It is a standard field on the Contact object.  The Contact object has a standard Account field.  Unless you create a custom email field on account, you will have to search contact records to get the AccountId to save to your custom account field on the lead.

Regards,

John

 
Domnic JohnsonDomnic Johnson
Hi John, 

What you say is true but, for a business account. When a org is enabled for Person account, Field from Contact Obj also become a part of Account Obj.

Regards