+ Start a Discussion

need to processing over 200000 records

Hi Guys,
I have a button in a s-control where I am calling webservice apex code in which i am copying more then 200000 records from master object with its child object to an other master object with its child object.I am recieving an error "Too many scripts 200001" statements.
is there any way to do effieciently as my apex webservice method code is below.Please review it and let me know how can I efficiently process these no of records without reaching  script statements governor limits?

for (List <CampaignScheduler__c> OpportunityDailySchedulesDates : [select Id,Campaign__c,Date__c,CurrencyIsoCode,Opportunity__c,Status__c from CampaignScheduler__c where Opportunity__c =: OppId])


List <CampaignScheduler__c> ClonedDailySchedules = new CampaignScheduler__c[]{};

for (Integer i=0; i < OpportunityDailySchedulesDates.size(); i++)


String CampId = OpportunityDailySchedulesDates[i].Campaign__c;

CampaignScheduler__c ClonedCampaignDailyScheduleDates = new CampaignScheduler__c();

ClonedCampaignDailyScheduleDates.Campaign__c = getMappedID(ListofAllCampaigns,CampId);

ClonedCampaignDailyScheduleDates.Opportunity__c = newOppId;

ClonedCampaignDailyScheduleDates.Date__c = OpportunityDailySchedulesDates[i].Date__c;

ClonedCampaignDailyScheduleDates.Status__c = OpportunityDailySchedulesDates[i].Status__c;

ClonedCampaignDailyScheduleDates.CurrencyIsoCode = OpportunityDailySchedulesDates[i].CurrencyIsoCode;



insert ClonedDailySchedules;