function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
kamal3883kamal3883 

Custom Reports

Hi,

 

I want to create a report on lead which shows all leads having same email id. Requirement is like this:

 

We need to create a link on Lead detail page which shows all leads having same email id as current Lead.

 

Can anybody suggest how can i acheive this.

 

Thanks 

GlynAGlynA

@kamal3883,

 

Instead of a link or a button, why not add a custom VisualForce page as an element on the Lead detail page layout.  That way, the duplicate Leads are displayed right on the page layout, and you don't have to click a link and navigate to a different page.

 

The VF page would be something like this:

 

<apex:page standardController="Lead" extensions="LeadEmailListController">
<apex:form>
    <apex:inputHidden value="{!Lead.Email}"/>
    <apex:dataTable value="{!otherLeads}" var="theLead">
        <apex:facet name="header">Leads with duplicate Email address:</apex:facet>
        <apex:column>
            <apex:facet name="header">Name</apex:facet>
            <apex:outputLink value="/{!theLead.Id}">{!theLead.Name}</apex:outputLink>
        </apex:column>
        <apex:column>
            <apex:facet name="header">Email</apex:facet>
            <apex:outputText value="{!theLead.Email}"/>
        </apex:column>
    </apex:dataTable>
    <apex:outputText value="There are no other Leads with the same Email address" rendered="{!noOtherLeads}"/>
</apex:form>
</apex:page>

 

And the controller extension will look like this:

 

public class LeadEmailListController
{
    private Lead theRecord;

    public List<Lead> otherLeads
    {
        get
        {
            if ( otherLeads == null )
            {
                otherLeads = [SELECT Id, Name, Email FROM Lead WHERE Email = :theRecord.Email];
            }
            return otherLeads;
        }
        private set;
    }

    public Boolean noOtherLeads { get { return otherLeads.isEmpty(); } }

    public LeadEmailListController( ApexPages.StandardSetController theController )
    {
        theLead = theController.getRecord();
    }
}

 

A caveat:  I have not compiled or tested this code, so there might be typos or other errors.  Please let me know if you find errors and I will correct them.

 

If this helps, please mark it as a solution, and give kudos (click on the star) if you think I deserve them. Thanks!

 

-Glyn Anderson
Certified Salesforce Developer | Certified Salesforce Administrator