+ Start a Discussion

copying of records | Presently available for 1 record | need for many records


I have piece of code like below
List<Account> accountList = [SELECT  Id, Name, Column1__c, Column2__c, Column3__c, ParentId
                             FROM Account 
                             WHERE Id = '001b000000r6WE3' LIMIT 1];

if(accountList  !=  null && accountList .size() > 0){
    CustomObject1__c cObjRec = new CustomObject1__c();
	cObjRec.Name = accountList[0].Name;
	cObjRec.Column1__c = accountList[0].Column1__c;
	cObjRec.Column2__c = accountList[0].Column2__c;
	cObjRec.Column3__c = accountList[0].Column3__c;  
       cObjRec.Parent_Account__c = 'a008E000001Vzxq';

       insert cObjRec;

In above code, I copy an account record (001b000000r6WE3) to new object CustomObject1__c.

How can i mass update (many accounts) at one time ?
Also what will be the limitations ?
I was planning to specify in where clause Record type = XYZ but this give 20000 records, so i need a solution.

Thank you for sugggesting
Best Answer chosen by Sandrine

1. You can insert 10000 record at a time use apex class or in develper console.

For this code is here 
List<CustomObject1__c> insertNewData = new Lsit<CustomObject1__c>();

for(Account c:[SELECT  Id, Name, Column1__c, Column2__c, Column3__c, ParentId FROM Account  WHERE recordType = 'XYZ' limit 9999])
    CustomObject1__c cObjRec = new CustomObject1__c();
	cObjRec.Name = c.Name;
	cObjRec.Column1__c = c.Column1__c;
	cObjRec.Column2__c = c.Column2__c;
	cObjRec.Column3__c = c.Column3__c;  
    cObjRec.Parent_Account__c = 'a008E000001Vzxq';

insert insertNewData;

2. Second way is you can create a report with same filter which you have applied in Query. Then run the report and download the file and save it as a CSV. After this in download file just change the field label of Account (First Row) to field label of  CustomObject1__c and then save it.

Now your field is ready and you can use dataloader or import wizard to upload the field data in your custom object.

3. If your data is more than 50000 than you can use batch class to do this.

Ashlekh Gera