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

Show Related Leads Based On Email Domain

Hi friends,

 i want to show leads which are associated with email domains on a visualforce page (which i use it in lead page layout).

For Ex :-

A lead with email is existing in my leads.
When a new lead is created with the same domain  Then the prevoius lead should be shown in the visualforce page (which i use it in lead page layout).

I tried it but could not get it solved : 

here is my Visualforce page and Extension controller, please do make any changes :

<apex:page standardController="Lead" extensions="GetDomain">
   <apex:pageBlock >
      <apex:pageBlockTable value="{!LeadLst}" var="ld">
         <apex:column value="{!ld.Name}"/>
         <apex:column value="{!ld.Email}"/>
         <apex:column value="{!ld.PartnerAccount.Name}" headerValue="Account"/>


public with sharing class GetDomain {

    public List<Lead> LeadLst { get; set; }

    public GetDomain(ApexPages.StandardController controller) {
        String email = '%' + [SELECT Name, Email, PartnerAccount.Name FROM Lead WHERE Id =: apexpages.currentpage().getparameters().get('id')].email.substringAfter('@')+ '%';
        LeadLst = [SELECT Name, Email FROM Lead WHERE Email LIKE: email];      


Did i miss anything that should be there.!

Any help would be approciated.

Avinash Guptha

Siddharth ManiSiddharth Mani
I tried your code in my DEV org and it seems to be working fine. Can you please tell me what is it that you are expecting and what is happening?
Also in case you want to ignore the Lead in context, you can modify your query like this:
LeadLst = [SELECT Name, Email FROM Lead WHERE Email LIKE: email and id!= :apexpages.currentpage().getparameters().get('id')];

This will only give you the related Leads not including the current one which is open.