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
vijay kumar kvijay kumar k 

i want vf page that exist two picklist values of account.here copy the contacts related to account(picklisi1) to paste all accontacts to selected another account(picklist) when click the custom button on vf page

i think u understood what iam asking here.
simlple ,in vf page contains two picklists and one custom button.both picklist values are same i.e all accounts.suppose i select one account at picklist1 and select another account at picklist2.and click custombutton,action do like this copy the all contacts related account who's select at picklist1 and paste duplicate contacts at who's select in picklist2.
u can  picklist names like 'contacts from account' and 'to account' .
thank you 
vijay kumar kvijay kumar k
i wrote code like below ,where iam wrong please resolve and send correct code if it is possible to you 
thank you 
apex class:
public class copycontact {
    public list<selectoption>account1{set;get;}
    public list<selectoption>account2{set;get;}
    public list<contact>contacts{set;get;}
    public String getListOfAccounts { get; set; }
    public id selectedaccountId1 {set;get;}
    public id selectedaccountId2 {set;get;}
    public list<id>selected ;
    public List<SelectOption> getListOfAccounts1()
    {
        List<Account> AccountList1 = [select id,Name from Account] ;
        System.debug('Accounts'+AccountList1.size());
        account1 = new List<SelectOption>();
        account1.add(new SelectOption( ' ' ,'---Select---'));
        for(Account acc : AccountList1 )
        {
            account1.add(new SelectOption(acc.id , acc.Name));
        }
        return account1 ;            
    }
    public List<SelectOption> getListOfAccounts2()
    {
        List<Account> AccountList2 = [select id,Name from Account] ;
        System.debug('Accounts'+AccountList2.size());
        account2 = new List<SelectOption>();
        account2.add(new SelectOption( ' ' ,'---Select---'));
        for(Account acc : AccountList2 )
        {
            account2.add(new SelectOption(acc.id , acc.Name));  
        }
        system.debug('java');
        return account2 ;  
    } 
    public  void clonecontacts(){
        system.debug('gsvdd');
        if(selectedaccountId1!=null){
            contacts=new list<contact>([select id,lastname from contact where accountid=:selectedaccountId1]);
            if(contacts.size()==0){
                system.debug('gsg'   );
                ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error,'No contacts to display'));
            }
            else{
                system.debug('dhg');
                for(Contact con:contacts){
                    con.accountid='selectedaccountId2';
                }
                update contacts;
            }
        }
    }
}

vf page :
<apex:page controller="copycontact">
<apex:form >
   <apex:pageBlock >
     <apex:pageBlockSection title="from Account" >
         <apex:OutputPanel >
              <apex:selectList value="{!selectedaccountId1}" size="1" multiselect="false" >
                  <apex:selectOptions value="{!ListOfAccounts1}"  />
               </apex:selectList>
          </apex:OutputPanel>
      </apex:pageBlockSection>
         </apex:pageBlock>
    <apex:pageBlock>
    <apex:pageBlockSection title="to account">
        <apex:selectList value="{!selectedaccountId2}" size="1" multiselect="false"  >
       <apex:selectOptions value="{!ListOfAccounts2}" />
        </apex:selectList>
       </apex:pageBlockSection> >
    </apex:pageBlock>
    <apex:commandButton value="clone" action="{!clonecontacts}"/>
    <apex:pageMessages ></apex:pageMessages>
</apex:form>
</apex:page>
Asitha_RajuAsitha_Raju
Hi Vijay,
Please try the below code for apex class:
public class copycontact {
    public list<selectoption>account1{set;get;}
    public list<selectoption>account2{set;get;}
    public list<contact>contacts{set;get;}
    public String getListOfAccounts { get; set; }
    public id selectedaccountId1 {set;get;}
    public id selectedaccountId2 {set;get;}
    public list<id>selected ;
    public List<SelectOption> getListOfAccounts1()
    {
        List<Account> AccountList1 = [select id,Name from Account] ;
        System.debug('Accounts'+AccountList1.size());
        account1 = new List<SelectOption>();
        account1.add(new SelectOption( ' ' ,'---Select---'));
        for(Account acc : AccountList1 )
        {
            account1.add(new SelectOption(acc.id , acc.Name));
        }
        return account1 ;            
    }
    public List<SelectOption> getListOfAccounts2()
    {
        List<Account> AccountList2 = [select id,Name from Account] ;
        System.debug('Accounts'+AccountList2.size());
        account2 = new List<SelectOption>();
        account2.add(new SelectOption( ' ' ,'---Select---'));
        for(Account acc : AccountList2 )
        {
            account2.add(new SelectOption(acc.id , acc.Name));  
        }
        system.debug('java');
        return account2 ;  
    } 
    public  void clonecontacts(){
        system.debug('gsvdd');
        if(selectedaccountId1!=null){
            System.debug('account id'+selectedaccountId1);
            contacts=new List<contact>([select id,lastname,accountId from contact where accountId = :selectedaccountId1]);
            System.debug(contacts);
            System.debug(contacts);
            if(contacts.size()==0){
                system.debug('gsg'   );
                ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error,'No contacts to display'));
            }
            else{
                system.debug('dhg');
                for(Contact con:contacts){
                    con.accountid=selectedaccountId2;
                }
                update contacts;
            }
        }
    }
}

Please select it as the best answer if it helps you.
Thanks​