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
Eric_ArizonaEric_Arizona 

Call sfdc accmergewizard from apex-visualforce

I need some help figuring out the best way to call salesforce.com/merge/accmergewizard.jsp? from a visual force page. The merge tool is very cool but limited to First Last name. I've taken the awesome code from Jeff Douglas apex-search-with-checkbox-results blog and modified it to search my person-acounts by email.
step 1
User-added image

User-added image
public class AccountMergeSearchController {

// -----------------------------------------------------------------------
// public class CategorySearchController {
// copied from Jeff Douglas code
// see http://blog.jeffdouglas.com/2009/01/13/apex-search-with-checkbox-results/

    // the results from the search. do not init the results or a blank rows show up initially on page load
    public List<AmsWrapper> searchResults {get;set;}
    // the categories that were checked/selected.
    public List<AmsWrapper> selectedAccounts {
        get {
            if (selectedAccounts == null) selectedAccounts = new List<AmsWrapper>();
            return selectedAccounts;
        }
        set;
    }      

    // the text in the search box
    public string searchText {
        get {
            if (searchText == null) searchText = 'email'; // prefill the serach box for ease of use
            return searchText;
        }
        set;
    } 

    // constructor
    public AccountMergeSearchController() {}

    // fired when the search button is clicked
    public PageReference search() {

        if (searchResults == null) {
            searchResults = new List<AmsWrapper>(); // init the list if it is null
        } else {
            searchResults.clear(); // clear out the current results if they exist
        }
        // Note: you could have achieved the same results as above by just using:
        // searchResults = new List<AmsWrapper>();

        // dynamic soql for fun
        String qry = 'SELECT a.Name, a.Id, a.CreatedDate, a.PersonEmail, a.City_St_Zip__c, a.Any_CI__c, a.Control_NumberFormulafield__c, a.Secondary_Name__c ' +
                      'FROM Account a ' +
                      'WHERE a.PersonEmail LIKE \'%'+searchText+'%\' ' +
                      'ORDER BY a.CreatedDate';
        // may need to modify for governor limits??
        for(Account a : Database.query(qry)) {
            // create a new wrapper by passing it the category in the constructor
            AmsWrapper aw = new AmsWrapper(a);
            // add the wrapper to the results
            searchResults.add(aw);
        }
        return null;
    }   

    public PageReference next() {

        // clear out the currently selected categories
        selectedAccounts.clear();

        // add the selected categories to a new List
        for (AmsWrapper aw : searchResults) {
            if (aw.checked)
                selectedAccounts.add(new AmsWrapper(aw.acct));
        }

        // ensure they selected at least one category or show an error message.
        if (selectedAccounts.size() > 1) {
            return Page.AmsResultVF;
            // *** My test code HERE ***
          // 1 PageReference pr = New PageReference('/merge/accmergewizard.jsp?' + 'goNext=+Next+' + '&cid=001e000000C1FwE' + '&cid=001e000000CqmcV');
          // 2 pr.getParameters().put('goNext','+Next+');
          // 2 pr.getParameters().put('cid','001200000012346');
          // 2 return pr;
            
        } else {
            ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Please select at least TWO Accounts.'));
            return null;
        }       

    }       

    // fired when the back button is clicked
    public PageReference back() {
        return Page.AccountMergeSearchVF;
    }       

}
 
public class AmsWrapper { 
   
// Account Merge Search Wrapper

    public Boolean checked{ get; set;}
    public Account acct { get; set;}

    public AmsWrapper(){
        acct = new Account();
        checked = false;
    }

    public AmsWrapper(Account a){
        acct = a;
        checked = false;
    }

}
 
<apex:page controller="AccountMergeSearchController">
    <apex:form >
        <apex:pageBlock mode="edit" id="block">

            <apex:pageBlockButtons location="bottom">
                <apex:commandButton action="{!next}" value="Merge Accounts" disabled="{!ISNULL(searchResults)}"/>
            </apex:pageBlockButtons>
            <apex:pageMessages />

            <apex:pageBlockSection >
                <apex:pageBlockSectionItem >
                    <apex:outputLabel for="searchText">Search for Accounts</apex:outputLabel>
                    <apex:panelGroup >
                    <apex:inputText id="searchText" value="{!searchText}"/>
                    <!-- We could have rerendered just the resultsBlock below but we want the  -->
                    <!-- 'Merge' button to update also so that it is clickable. -->
                    <apex:commandButton value="Search" action="{!search}" rerender="block" status="status"/>
                    </apex:panelGroup>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>

            <apex:actionStatus id="status" startText="Searching... please wait..."/>
            <apex:pageBlockSection title="Search Results" id="resultsBlock" columns="1">
                <apex:pageBlockTable value="{!searchResults}" var="a" rendered="{!NOT(ISNULL(searchResults))}">
                    <apex:column width="25px">
                        <apex:inputCheckbox value="{!a.checked}"/>
                    </apex:column>
                    <apex:column value="{!a.acct.Name}"/>
                    <apex:column value="{!a.acct.Id}"/>
                    <apex:column value="{!a.acct.Secondary_Name__c}" headerValue="Secondary"/>
                    <apex:column value="{!a.acct.PersonEmail}"/>
                    <apex:column value="{!a.acct.Control_NumberFormulafield__c}" headerValue="Control #"/>
                    <apex:column value="{!a.acct.City_St_Zip__c}"/>
                    <apex:column value="{!a.acct.CreatedDate}"/>
                    <apex:column value="{!a.acct.Any_CI__c}"/>
                </apex:pageBlockTable>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>
 
<apex:page controller="AccountMergeSearchController">
    <apex:form >
        <apex:pageBlock >

            <apex:pageBlockButtons >
                <apex:commandButton action="{!back}" value="Back"/>
            </apex:pageBlockButtons>
            <apex:pageMessages />

            <apex:pageBlockSection title="You Selected" columns="1">
                <apex:pageBlockTable value="{!selectedAccounts}" var="a">
                    <apex:column value="{!a.Acct.Name}"/>
                </apex:pageBlockTable>
                <apex:outputLink value="https://cs15.salesforce.com/merge/accmergewizard.jsp?goNext=+Next+&cid=001e000000C1FwE&cid=001e000000CqmcV">Click to Merge</apex:outputLink>
            </apex:pageBlockSection>           
        </apex:pageBlock>
    </apex:form>
</apex:page>

 
Eric_ArizonaEric_Arizona
I tried using PageReference like this

PageReference pr = New PageReference('/merge/accmergewizard.jsp?' + 'goNext=+Next+' + '&cid=001e000000C1FwE' + '&cid=001e000000CqmcV');

but SF reformated the pr, it doesnt like mutiple values with the same name &cid, &cid ...

then I thought maybe using output link somehow so I hardcoded some values in the AmsReslutVF page above that may work but I'm not sure how to load the values.

Ideally what I'm trying to accomplish is:
  1. input an email address press search button 
  2. get a screen of matches, put a check next to the ones I want to Merge, press merge button
  3. bring up the merge/accmergewizard
Thank, Eric Jones