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 

Merge Multiples Accounts by Selecting a CheckBox

I have an app to show iteratively the IDs by selecting a checkBox. I need to merge the selected accounts, how can I do that?
This is the Controller:
 
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;}


 // CONSTRUCTOR
 public MyAccountListCntrlr(){
      acctList = new List<AccountWrapperCls>();
      selAccountNames = new Set<String>();
     showMessage = false;
      for(Account a : [SELECT AccountNumber, name, id, phone, fax, website, type, industry, description, NumberOfEmployees, BillingCity, AnnualRevenue from account
      LIMIT 10]){
           acctList.add(new AccountWrapperCls(a));
      }
 }

 // METHODS
 public void displaySelectedAccountNumbers(){
      //selAccountNames.clear();
      hasSelAcct = false;
      for(AccountWrapperCls cWrapper : acctList){
           if(cWrapper.isSelected){
                hasSelAcct = true;
                selAccountNames.add(cWrapper.cAccount.id);
                //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;
                } 
            }
      }
   }
I am also use a Wrapper Class such the following:
public class AccountWrapperCls {
 public Boolean isSelected {get;set;}
 public Account cAccount {get;set;}     

 public AccountWrapperCls(Account cAccount){
      this.cAccount = cAccount; } }//End AccountWrapperCls

And this is the VisualForce Page:
 
<apex:page controller="MyAccountListCntrlr" tabStyle="Account">

<!-- ACCOUNT LIST -->
     <apex:pageBlockTable value="{!acctList}" var="acctWrapper">
        <apex:column >
           <apex:inputCheckbox value="{!acctWrapper.isSelected}"/>
        </apex:column> 
        <apex:column value="{!acctWrapper.cAccount.AccountNumber}"/>
        <apex:column value="{!acctWrapper.cAccount.Name}"/>
         <apex:column value="{!acctWrapper.cAccount.website}"/>
     </apex:pageBlockTable>

      <!--//Message-->
         <apex:outputText rendered="{!showMessage}" id="tests">
             <script>
             alert("{!JSENCODE(message)}")
             </script>
         </apex:outputText>

     <!-- SELECTED ACCOUNT INFO -->
     <apex:pageBlockSection >
        <apex:outputPanel layout="block" rendered="{!hasSelAcct}">
           <apex:outputText value="Below are the selected account:"/>
           <br/>
           <apex:outputText value="{!selAccountNames}"/>
         </apex:outputPanel>
         <apex:outputPanel layout="block" rendered="{!NOT(hasSelAcct)}">
            <br/>
            <apex:outputText value="No account selected."/>
         </apex:outputPanel>
     </apex:pageBlockSection>
  </apex:pageBlock>

How can I merge the selected accounts? Any ideas or code? Thanks in advance.
 
reymagdaongreymagdaong
1. What do you mean by merge? merging 1 or multiple accounts into 1 new account record? that are the rules in merging? 
2. Or you just want to display the selected accounts in a section? if that's the case you just rerender the section.