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
Rodolfo Calvo 3Rodolfo Calvo 3 

Error at merging Database.MergeResult[]

Hello team, 

I am developing a merging app but I cannot find to way to merge what I need. A have a multiple selection for all the accounts I want to merge and the Master Account. 
Here is the code: 
public class MyAccountListCntrlr {
    public List<AccountWrapperCls> acctList {get;set;}
    public Set<String> selAccountNames {get;set;}
    public Boolean hasSelAcct {get;set;}
    public static List<Account> accts;
    //	MESSAGE
    public static  Boolean showMessage {get;set;}
	public static String message {get;set;}
    public static List<Account> acct;//Account 1
    public static List<Account> acct2;//Account 2
    public static String sAccount{set;get;}//Selection of the Master Account
    //See the method getItems
     public MyAccountListCntrlr(){
          acctList = new List<AccountWrapperCls>();
          selAccountNames = new Set<String>();
         showMessage = false;
          for(Account a : [SELECT AccountNumber, CreatedDate, name, id, phone, fax, website, type, industry, description, NumberOfEmployees, BillingCity, AnnualRevenue from account
          ORDER BY Account.Name]){
               acctList.add(new AccountWrapperCls(a));
    public List<SelectOption> getItems() 
        List<Account> lstAcc = [select id, name from account ORDER BY Account.Name];
        List<SelectOption> options = new List<SelectOption>();
        for(Account acc : lstAcc)
            options.add( new SelectOption(, acc.Name));
        return options;
   public Account masterAcc = new account(name = sAccount);
     // METHODS
     public void displaySelectedAccountNumbers(){
          //masterAcc = [Select name from Account where name = :sAccount];
          hasSelAcct = false;
          for(AccountWrapperCls cWrapper : acctList){
                    hasSelAcct = true;
                   	//showMessage = true;
                   	//message = 'The following error has ocurred: \n' +;
               if(selAccountNames.size() > 1)
                    for(Integer i = 1; i < selAccountNames.size(); i++)
                        showMessage = true;
                        message = 'The selected accounts are: \n' + selAccountNames;
                        acct = [Select id, name, phone FROM Account where id = :selAccountNames];
                        //acct2 = [Select id, name, phone FROM Account where id = :selAccountNames ORDER BY Account.CreatedDate];
                        message = 'The selected query is: \n' + acct;
                        if(selAccountNames.size() > 1)
                                //acct.get(i).description = '\nAccount Name: ' + acct.get(0).Name;
                                Database.MergeResult[] results = Database.merge(masterAcc, acct, false);
                                //merge acct.get(0) acct2.get(i); 
                                //merge acct2.get(i) master.get(1);
                                //If the first Account was created first than 2nd one then do not merge
                                /*if(acct.get(0).CreatedDate < acct.get(i).CreatedDate)
                                    acct.get(0).description = '\nAccount Name: ' + acct.get(i).Name;
                                    merge acct.get(i) acct2.get(0);     
                                    acct.get(i).description = '\nAccount Name: ' + acct.get(0).Name;
                                    merge acct.get(0) acct2.get(i); 
                            catch(Exception e)
                                showMessage = true;
                                message = 'The following error has founded: ' + e;
                    showMessage = true;
                    message = 'Congratulations, you have merge successfully your accounts, please refresh the site to see changes. ';
    public PageReference PreviousPag()
        return Page.LCA;

Can somebody help me out with this issue?
Thanks in advace. 
Michael DsozaMichael Dsoza
Plesae post the error message.
Seva Tsurikov 2Seva Tsurikov 2

The error is in line 80: "Database.MergeResult[]" - the result of a merge will be a single record, not the array.

Change to

Database.MergeResult results = Database.merge(masterAcc, acct, false);