You need to sign in to do that
Don't have an account?
MrHammy
bulkifiing issue
My class is now working and doing everything I want with the exception of large result sets. My public PageReference Save is a for loop and calls another class that is making way to many DML calls. Its the end of the day and I thought I would ask if anyone can point me at a way to bulkify this a little bit, I know what's wrong I just can't find the fix yet.
Thanks for all the help
public class MultiRow { public List<multiRowContact> Contacts { get; set; } String chainname, prog, filter; String idx = ApexPages.currentPage().getParameters().get('idx') ; public PageReference cancel() { return new PageReference('/'+idx); } public MultiRow() { chainname = ApexPages.currentPage().getParameters().get('name') ; prog = ApexPages.currentPage().getParameters().get('pg') ; if(prog == 'WM Synergy'){ filter = '0128000000020mOAAQ'; //WM Synergy } else if (prog == 'PS Cornerstone') { filter = '0128000000020mTAAQ'; //PS Cornerstone } else if (prog == 'CB Ascend') { filter = '0128000000020mVAAQ'; //CB Ascend } else { filter = ''; } LoadData(); } private void LoadData() { Contacts = new List<multiRowContact>(); for (List<erp_data__c> cs : [SELECT name, Account__c ,Acct_RT_Name__c, Chain__c,Id, Program__c, RecordTypeId , updatetowhat__c FROM ERP_Data__c WHERE Chain__c = :chainname and RecordTypeId = :filter limit 25]) { for (erp_data__c c : cs) { multiRowContact MRC = new multiRowContact(); MRC.ID = c.ID; MRC.Checked = true; MRC.Name = c.Name; MRC.Program = c.Program__c; MRC.account = c.Account__c ; MRC.updatetowhat = prog; Contacts.add(MRC); } } } public PageReference Save() { for (multiRowContact MRC : Contacts) { MRC.Save(); } //LoadData(); return new PageReference('/'+idx); } private class multiRowContact { String prog = ApexPages.currentPage().getParameters().get('pg') ; String idx = ApexPages.currentPage().getParameters().get('idx') ; public String ID { get; set; } public String Name { get; set; } public String Account { get; set; } public String updatetowhat{ get; set; } public String Program { get; set; } public Boolean Checked { get; set; } List<Participating_Branch_Locations__c > updatedList = new List<Participating_Branch_Locations__c >(); List<erp_data__c > updatedList_erp = new List<erp_data__c >(); public void Save() { if (Checked) { //select account__c from Participating_Branch_Locations__c where Distributor_Program__c = idx list <Participating_Branch_Locations__c > ids = [select account__c from Participating_Branch_Locations__c where Distributor_Program__c = :idx]; if( 1 == 2){ } else { System.debug('Saving...ID: ' + ID); erp_data__c c = [SELECT c.updatetowhat__c FROM erp_data__c c WHERE c.ID = :ID LIMIT 1]; c.updatetowhat__c = prog; updatedList_erp.add(c); Participating_Branch_Locations__c newpbl = new Participating_Branch_Locations__c (Account__c = Account ,Distributor_Program__c = idx); updatedList.add(newpbl); } } insert updatedList; update updatedList_erp; } } }
You're going to have to refactor the save inside the MultiRowContact class so that it sets up the records to insert/update but doesn't carry out the insert.
The way I'd handle this is to create the lists in the MultiRow class and pass these as parameters to each call of the MultiRowContact.save() method.
The MultiRow save method becomes:
and the MultiRowContact save method becomes:
All Answers
You're going to have to refactor the save inside the MultiRowContact class so that it sets up the records to insert/update but doesn't carry out the insert.
The way I'd handle this is to create the lists in the MultiRow class and pass these as parameters to each call of the MultiRowContact.save() method.
The MultiRow save method becomes:
and the MultiRowContact save method becomes: