Searching existing contacts based on a lead

I went to the London user group last year and quite a few people were interested in an app which when your looking at a lead automatically searches for existing records within salesforce. So I’ve just created a quick Salesforce app to allow you to search existing contacts based on a lead. It only searches contacts at the moment but I’ll get it to search other objects too if people are interested in it. Its also limited to just searching based on email address at the moment as well, but again if people are interested i’ll expand it.

If you want it give me a shout and i’ll send you a link to the package so that you can install it in your org, a “one click” install. But if your feeling adventuous and want to do it manually you can follow the brief instructions below, but you do need to know the basics of how to edit and create apex classes and pages:

Create searchContacts class:

public with sharing class searchContacts {

private final Lead thisLead;
public Contact [] contactObj { get; private set; }

public searchContacts(ApexPages.StandardController stdController) {
this.thisLead = (Lead)stdController.getRecord();

}

public Contact [] getContacts(){

System.debug(‘controller Id: ‘ + this.thisLead.Id);

Lead EmailAddress = [Select l.Email from Lead l WHERE l.Id = :this.thisLead.Id];

System.debug(‘getContacts Lead: ‘ + EmailAddress);

contactObj = [Select
c.Name,
c.AccountId,
c.Email,
c.FirstName,
c.Id,
c.LastName,
c.Salutation,
c.Title
from Contact c
WHERE c.Email = :EmailAddress.Email ];

return contactObj;
}
}

Create a searchContacts Page:
<apex:page standardController="Lead" extensions="searchContacts">
<apex:pageBlock >
<apex:pageBlockTable value="{!contacts}" var="item">
<apex:column value="{!item.Name}" />
<!--            <apex:column value="{!item.Id}" />-->
<apex:column value="{!item.AccountId}"/>
<apex:column value="{!item.Title}" />
<apex:column value="{!item.Email}" />
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>

In the page above i’ve just pulled out Name, AccountId, Title & Email fields, but if you have custom fields or other fields you want to pull out just copy one of the apex:column lines and change the field name (!item.xxxxx)

Next all you need to do is add the visualforce page to the Lead page layout, also don’t forget if you have different profiles that you go in to them and give access to the visualforce page otherwise other users won’t be able to see the visualforce page.

Bingo!

Load More Related Articles
  • The Salesforce Learning Week!

    What a year! It’s around this time of year when I would be heading to Dreamforce (Salesforce’s biggest event of the ...
  • The Salesforce Capability Map

    The Salesforce platforms are huge and sometimes it’s hard to keep up with all the changes. These Salesforce capability maps are ...
  • New Salesforce News Podcast!

    So Anup and I have decided to create a new Salesforce podcast called the ‘Salesforce Posse Podcast’. We’ve just launched our ...
Load More By Francis Pindar
Load More In Salesforce.com

3 Comments


  1. […] This post was mentioned on Twitter by Setup Salesforce, Francis. Francis said: Just created a quick Salesforce app to automaticly search contacts from a lead to help reduce duplicates. http://bit.ly/fUW9eS […]

  2. […] Home « Searching existing contacts based on a lead […]

  3. Adam

    May 11, 2011 at 4:31 pm

    Hey,

    great idea!

    As someone who is new to SFDC dev I’d definately be interested in a ‘one click’ install. Would you be able to provide for me please?

    Thanks

    Adam

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Check Also

The Salesforce Learning Week!

What a year! It’s around this time of ...

My Latest YouTube Video