+ Start a Discussion

Custom Account Merge using Billing Address


I am developing custom account merge page, is there any way I can pass account ids to a JSP by selecting accounts from the list?


I should be able to select only 2 accounts from list.

Right now I am able to merge two account by dynamically passing the CID1 and CID2 which works fine. My requirement is I should be able to select any of 2 accounts from the list and should be pass the selected account Ids to merge wizard.


Appreciate any help


///***************** Controller *******************///
public class AccountSearchController {
    //added an instance varaible for the standard controller
    private ApexPages.StandardController controller {get; set;}
    // the actual account
    public Account a;
    public Account s;
    pagereference p = null;
    public string current_Id {get; set;}    
    public string sid1 {get; set;}
    public string sid2 {get; set;}
    public List<Account> searchResults {get;set;}
    public List<QResult> QResultList{get; set;}
    public string BillingStreet {
    get {
        if (BillingStreet == null) BillingStreet = ''; // prefill the search box for ease of use
        return BillingStreet;
    public string BillingCity {
    get {
        if (BillingCity == null) BillingCity = ''; // prefill the search box for ease of use
        return BillingCity ;

    public string BillingPostalCode {
    get {
        if (BillingPostalCode == null) BillingPostalCode = ''; // prefill the search box for ease of use
        return BillingPostalCode ;
    public string BillingState {
    get {
        if (BillingState == null) BillingState = ''; // prefill the search box for ease of use
        return BillingState;
    public AccountSearchController(ApexPages.StandardController controller) {
        //initialize the stanrdard controller
        this.controller = controller;
        this.a = (Account)controller.getRecord();
        system.debug('AccountRec: ' +a);
        s=[ SELECT Id,Name,BillingStreet,BillingCity,BillingState,BillingPostalCode FROM Account WHERE Id=:a.Id];
        BillingStreet =s.BillingStreet;
    // fired when the search button is clicked
    public PageReference search()
        if (searchResults == null) {
            searchResults = new List<Account>(); // init the list if it is null
        } else {
            searchResults.clear(); // clear out the current results if they exist
     // Use Dynamic SOQL to find the account based on user input
        String qry = 'Select o.Id,o.Name,o.BillingStreet,o.BillingCity,o.BillingState,o.BillingPostalCode from account o Where BillingStreet LIKE \'%'+BillingStreet+'%\' AND BillingCity LIKE \'%'+BillingCity+'%\' AND BillingState LIKE \'%'+BillingState+'%\' AND BillingPostalCode LIKE \'%'+BillingPostalCode+'%\' AND Id!=\''+a.Id+'\' ORDER By o.Name';

        searchResults = Database.query(qry);

        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'No Records Found'));
       return null;
     public PageReference amerge()
         return null;  
    public class QResult{        
        public account acc {get; set;}        
        public string  pid  {get; set;}
        public Boolean selected {get; set;}        
        //This is the contructor method. When we create a new cContact object we pass a Contact that is set to the con property. We also set the selected value to false        
        public QResult(account a) {            
        acc = a;            
        selected = false;        


//************** VF Page        ***************************//
<apex:page standardController="Account" extensions="AccountSearchController">
    <style type="text/css">
        body {background: #F3F3EC; padding-top: 15px}
    <apex:form title="Merger"  >
        <apex:pageBlock title="Accounts with same Billing Address" id="block" mode="detail">        
            <apex:pageMessages />
                <apex:pageBlockSection title="Search by" columns="1" id="detail"  collapsible="false">      
                    <apex:outputpanel id="thePanel" style="">       
                      <apex:pageblockSectionItem id="id1" labelStyle="font-weight:600" >
                        <apex:outputLabel style="font-weight:600;padding-left:0px;padding-right:80px"> Billing Street</apex:outputLabel>                                           
                      <apex:pageblockSectionItem >                       
                         <apex:outputLabel style="font-weight:600;padding-left:35px;padding-right:120px"> Billing City     </apex:outputLabel>                                           
                      <apex:pageblockSectionItem >
                         <apex:outputLabel style="font-weight:600;padding-left:5px;padding-right:80px"> Billing Zip Code </apex:outputLabel>                                           
                      <apex:pageblockSectionItem >
                         <apex:outputLabel style="font-weight:600;padding-left:20px;padding-right:50px"> Billing State    </apex:outputLabel>                                                                                     
                        <apex:inputText style="padding-left:0px;padding-right:50px" id="bs" value="{!BillingStreet}"  label="Billing Street"/>                   
                        <apex:inputText style="padding-left:0px;padding-right:50px" id="bc" value="{!BillingCity}"  label="Billing City   "/>                     
                        <apex:inputText style="padding-left:0px;padding-right:50px" id="bz" value="{!BillingPostalCode}"  label="Billing Zipcode   "/>                     
                        <apex:inputText style="padding-left:0px;padding-right:50px" id="bst" value="{!BillingState}"  label="Billing State   "/>                                  
            <apex:pageBlockSection >
                <apex:panelGroup style="align:left" >
                    <apex:commandButton value="Search" action="{!search}" rerender="resultsBlock" status="status"/>

            <apex:actionStatus id="status" startText="Searching... please wait..."/>
            <apex:pageBlockSection id="resultsBlock" columns="1">
                <apex:pageBlockTable value="{!SearchResults}" var="o" rendered="{!NOT(ISNULL(SearchResults))}">

<!--    <apex:column headerValue="Key Values">  
    <apex:column headerValue="Values">  
    </apex:column>  -->

                    <apex:column headerValue="Name">
                        <apex:outputLink value="/{!o.Id}">{!o.Name}</apex:outputLink>
                    <apex:column value="{!o.BillingStreet}"/>
                    <apex:column value="{!o.BillingCity}"/>
                    <apex:column value="{!o.BillingPostalCode}"/>
                    <apex:column value="{!o.BillingState}"/>
                    <apex:column >
                        <apex:commandbutton action="/merge/accmergewizard.jsp?goNext&cid={!sid1}&cid={!o.Id}" value="Merge" id="Merge" rendered="true" >