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!

Be Sociable, Share!