You need to sign in to do that
Don't have an account?

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:
Can somebody help me out with this issue?
Thanks in advace.
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 { // PROPERTIES 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 // CONSTRUCTOR 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)); } } // SELECTING MASTER 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.id, acc.Name)); options.sort(); } return options; } public Account masterAcc = new account(name = sAccount); // METHODS public void displaySelectedAccountNumbers(){ //selAccountNames.clear(); //masterAcc = [Select name from Account where name = :sAccount]; hasSelAcct = false; for(AccountWrapperCls cWrapper : acctList){ if(cWrapper.isSelected){ hasSelAcct = true; selAccountNames.add(cWrapper.cAccount.name); //showMessage = true; //message = 'The following error has ocurred: \n' + cWrapper.cAccount.id; //accts.add(cWrapper.cAccount); } 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) { try { //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); } else { 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.
Plesae post the error message.
Thanks
The error is in line 80: "Database.MergeResult[]" - the result of a merge will be a single record, not the array.
Change to