Hi All,
I am facing bulkification issue on creating multiple child records from insert multiple parent record using data loader. It's showing "10:53:29:088 FATAL_ERROR System.LimitException: Too many DML rows: 10001".
Please help me for fixing the issue.
trigger OppTrigger on Opportunity (after insert, after update, before delete) {
// Record Insert Code if(trigger.isInsert || trigger.isundelete){ if(checkRecursive.runOnce()){ Set<Id> oppId = new Set<Id>(); Map<Id,Opportunity> oppmap = new Map<Id,Opportunity>(); for(Opportunity opp: Trigger.new){ oppId.add(opp.Id); } List<Projected_Opportunity__c> proOppList = new List<Projected_Opportunity__c>(); for(Opportunity opps: [SELECT ID,Name,StageName,Probability, CloseDate,Month_No__c,Implementation_Date__c, Contract_Term__c,Amount,Projected_Revenue_1__c, Q1RF_target__c,Total_Project_Revenue__c FROM Opportunity WHERE ID IN:oppId]){ for(Integer i=0; i< Integer.valueOf(opps.Contract_Term__c); i++){ Projected_Opportunity__c po = new Projected_Opportunity__c(); po.Opportunity__c = opps.Id; po.Opportunity_Name__c = opps.Name; po.Stage__c = opps.StageName; po.Probability__c = opps.Probability; po.Closed_Date__c = opps.CloseDate; po.Month_No__c = opps.Month_No__c; po.Projected_Implementation_Date__c = opps.Implementation_Date__c.addMonths(i); po.Contract_Term__c=opps.Contract_Term__c; po.Amount__c = opps.Amount; po.Monthly_Projected_Revenue__c = opps.Projected_Revenue_1__c; po.Target_Revenue__c = opps.Q1RF_target__c; po.Total_Project_Revenue__c = opps.Total_Project_Revenue__c; proOppList.add(po); } } if(!proOppList.isEmpty()){ insert proOppList; } /* List<Projected_Opportunity__c> polistInsertRecords = new List<Projected_Opportunity__c>(); for(Opportunity opps: Trigger.new){ for(Integer i=0; i< Integer.valueOf(opps.Contract_Term__c); i++){ Projected_Opportunity__c po = new Projected_Opportunity__c(); po.Opportunity__c = opps.Id; po.Opportunity_Name__c = opps.Name; po.Stage__c = opps.StageName; po.Probability__c = opps.Probability; po.Closed_Date__c = opps.CloseDate; po.Month_No__c = opps.Month_No__c; po.Projected_Implementation_Date__c = opps.Implementation_Date__c.addMonths(i); po.Contract_Term__c=opps.Contract_Term__c; po.Amount__c = opps.Amount; po.Monthly_Projected_Revenue__c = opps.Projected_Revenue_1__c; po.Target_Revenue__c = opps.Q1RF_target__c; po.Total_Project_Revenue__c = opps.Total_Project_Revenue__c; polistInsertRecords.add(po); } } system.debug('polistInsertRecords ' + polistInsertRecords); if(!polistInsertRecords.isEmpty()){ insert polistInsertRecords; }*/ /*try{ if(polistInsertRecords.size() >0){ insert polistInsertRecords; system.debug('Record Inserted...'); } }catch(DmlException e){ system.debug(e.getMessage()); system.debug(e.getLineNumber()); } */ } } //Code for update records if(trigger.isUpdate){ if(checkRecursive.runOnce()){ Set<Id> oppids = new Set<Id>(); List<Projected_Opportunity__c> polistInsertRecords = new List<Projected_Opportunity__c>(); for(Opportunity op : trigger.new){ oppids.add(op.id); } List<Projected_Opportunity__c> proOppForDel = new List<Projected_Opportunity__c>([Select Id,Opportunity_Name__c,Amount__c, Closed_Date__c,Stage__c,Probability__c, Projected_Implementation_Date__c,Contract_Term__c, Monthly_Projected_Revenue__c,Target_Revenue__c From Projected_Opportunity__c Where Opportunity__c IN:oppids]); Delete proOppForDel; for(Opportunity opps : Trigger.new){ for(Integer i=0; i< opps.Contract_Term__c; i++){ Projected_Opportunity__c po = new Projected_Opportunity__c(); po.Opportunity__c = opps.Id; po.Opportunity_Name__c = opps.Name; po.Stage__c = opps.StageName; po.Probability__c = opps.Probability; po.Closed_Date__c = opps.CloseDate; po.Month_No__c = opps.Month_No__c; po.Projected_Implementation_Date__c = opps.Implementation_Date__c.addMonths(i); po.Contract_Term__c=opps.Contract_Term__c; po.Amount__c = opps.Amount; po.Monthly_Projected_Revenue__c = opps.Projected_Revenue_1__c; po.Target_Revenue__c = opps.Q1RF_target__c; po.Total_Project_Revenue__c = opps.Total_Project_Revenue__c; polistInsertRecords.add(po); } }system.debug('polistInsertRecords ' + polistInsertRecords); try{ if(polistInsertRecords.size() >0){ insert polistInsertRecords; system.debug('Record Inserted...'); } }catch(DmlException e){ system.debug(e.getMessage()); system.debug(e.getLineNumber()); } } }}15 answers
Hey Glyn,
The issue is fixed now. Thanks for your support.
Now I am stuck on a new logic.
I need to set a default picklist value in VF page when it's loading.
What should I do, I don't have any idea.
I have updated the constructor to display the default value but it's not working.
Controller Code: -
global string Shift_Cancellation_Status { get; set; }
// the list of Shift Cancellation Status List global list<SelectOption> Shiftss_Cancellation_Status_List { get { list<SelectOption> listSO =new list<SelectOption>(); //listSO.add(new selectoption('','(all shift cancellation status)')); listSO.add(new selectoption('all shift cancellation statuses','(all shift cancellation statuses)')); listSO.add(new selectoption('Canceled by Organization = FALSE','Canceled by Organization = FALSE')); listSO.add(new selectoption('Canceled by Organization = TRUE','Canceled by Organization = TRUE')); return listSO; } set; } VFPAGE code: - <div class="slds-form-element"> <apex:outputLabel value="Shift Cancellation Status" for="ddlShiftCancellationStatus" styleClass="slds-form-element__label" /> <div class="slds-form-element__control"> <div class="slds-select_container"> <apex:selectList id="ddlShiftCancellationStatus" value="{!Shift_Cancellation_Status}" size="1" styleClass="slds-select" > <apex:actionSupport immediate="false" event="onchange" rerender="panelPrint" status="retrieveStatus" action="{!ChangeShiftCancellationStatus}" /> <apex:selectOptions value="{!Shift_Cancellation_Status_List}" /> </apex:selectList> </div> </div></div>
Plz help me!