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
Kiru535Kiru535 

List out Duplicate records on account object like Lead object

I got requirement like on Account detail record create one button called "Find Duplicates".When click on this button  invoke the VF page to display the list of duplicate record matching with the current record.

 

I am dng the account matching based on Account name,website, Country,City

 

Please help me ASAP how to do with Apex class and VF page.....

 

Regards,

Kiran

Kiru535Kiru535
Please reply ASAP if anyone knows.....
hitesh90hitesh90

Hi Kiran,

 

You have to put soql query on Account objent in your controller and put where condition as per your requirement(matching based on Account name,website, Country,City).  after this you will get List of Account Record. now using pageblocktable you can display this Account record to Visualforce Page.

 

Important :
If this answer is helpful to you, please mark this as the best answer.

Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator

Kiru535Kiru535

Thanks for the reply...

 

My code is working fine but with small issue... When I click on Find Duplicate Button on account detail dispalying the current record in VF page even if doesn't match the duplicates. And I want code like If Account list.Size()>=1 return to  VF page otherwise show the Apex message like " No Duplicates found related to this record".

 

Please post me the code to achive this scenario.

 

Controller:

public class AccountDupController
{
Account acc;
String acname;
String web;
List<Account> accountStd;

public List<Account> searchResults {get;set;}

private ApexPages.StandardController controller {get;set;}


public AccountDupController(ApexPages.StandardController controller) {

//initialize the stanrdard controller

this.controller = controller;
this.acc = (Account)controller.getRecord();
accountStd = [SELECT Name,Website FROM Account where ID=:acc.id];
acname = accountStd[0].Name;
system.debug ('***** Name is*****'+acname);
web = accountStd[0].Website;
system.debug ('***** Name is*****'+web);

}
public PageReference search()
{
searchResults =[SELECT Name,Website FROM Account where Name=:acname AND Website=:web];
system.debug('*****The results*****'+searchResults);
return null;
}
}

 

VF page:

 

<apex:page standardController="Account" extensions="AccountDupController" action="{!search}">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection title="Results" id="searchResults" columns="1">
<apex:pageBlockTable value="{!searchResults}" var="o">

<apex:column headerValue="Account Name">
<apex:outputLink value="/{!o.id}" target="Account">{!o.Name}</apex:outputLink>
</apex:column>
<apex:column headerValue="Website"/>
<apex:column value="{!o.Website}">
</apex:column>
 </apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>

</apex:page>

 

 

hitesh90hitesh90

Hi kiran,

 

Here is your code.

Visualforce Page:

<apex:page standardController="Account" extensions="AccountDupController" action="{!search}">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection title="Results" id="searchResults" columns="1">
                <apex:pageBlockTable value="{!searchResults}" rendered="{!If(searchResults.size > 1,true,false)}" var="o">    
                <apex:column headerValue="Account Name">
                <apex:outputLink value="/{!o.id}" target="Account">{!o.Name}</apex:outputLink>
                </apex:column>
                <apex:column headerValue="Website"/>
                <apex:column value="{!o.Website}">
                </apex:column>
             </apex:pageBlockTable>
             <apex:outputPanel rendered="{!If(searchResults.size > 1,false,true)}">
                 No Duplicates found related to this record
             </apex:outputPanel>
         
        </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 

Apex Class:

public class AccountDupController{
    Account acc;
    String acname;
    String web;
    List<Account> accountStd;    
    public List<Account> searchResults {get;set;}    
    private ApexPages.StandardController controller {get;set;}    
    public AccountDupController(ApexPages.StandardController controller) {        
        //initialize the stanrdard controller        
        this.controller = controller;
        this.acc = (Account)controller.getRecord();
        accountStd = [SELECT Name,Website FROM Account where ID=:acc.id];
        acname = accountStd[0].Name;
        system.debug ('***** Name is*****'+acname);
        web = accountStd[0].Website;
        system.debug ('***** Name is*****'+web);    
    }
    public PageReference search(){
        searchResults =[SELECT Name,Website FROM Account where Name=:acname AND Website=:web];
        system.debug('*****The results*****'+searchResults);
        return null;
    }
}

Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
 
Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator

 

 

Praveen Kumar BonaluPraveen Kumar Bonalu
hi Hitesh ,
 i found the errors  "list index out of bound expection " at line 13 and 15 can you please say how to slove the problem
thanks 
Praveen Kumar BonaluPraveen Kumar Bonalu
I got requirement like on lead  detail record create one button called "Find Duplicates".When click on this button  invoke the VF page to display the list of duplicate record matching with the current record.

I am dng the lead  matching based on First name,Lastname, company,Email.

Please help me ASAP how to do with Apex class and VF page.....

Thanks