Hi I am doing a counter, which if the for loop reaches 100 records to add into my array and then update the records in the database... But if there are more then 100 records then to clear our the list and do the for loop again to make sure everything is updated...
I have no idea what am I doing wrong but it is not working...
Also I need it to break if there are no more records...
Thanks
I have no idea what am I doing wrong but it is not working...
Also I need it to break if there are no more records...
Code:
Integer x;
Integer y;
List<Contact_Membership__c> cntMembers = new List<Contact_Membership__c>();
for (x=0; x<2; x++)
{
System.Debug('step1- ' + x);
for(y=0; y<100; y++)
{
for(Contact_Membership__c oCMs : [select Id, Account_Membership__c from Contact_Membership__c where Account_Membership__c in :acctMemberMap.keySet()])
{
System.Debug('step2- ' + y);
Account_Membership__c accMem = acctMemberMap.get(oCMs.Account_Membership__c);
if(accMem.Status__c == 'Member')
{
oCMs.Status__c = 'Member';
oCMs.Type__c = 'Corporate';
oCMs.Joined__c = accMem.Joined__c;
oCMs.Expires__c = accMem.Expires__c;
oCMs.OwnerId = accMem.OwnerId;
}
else if(accMem.Status__c == 'Expired Member')
{
oCMs.Status__c = 'Expired Member';
oCMs.Type__c = 'Pre-Qualified';
oCMs.Joined__c = accMem.Joined__c;
oCMs.Expires__c = accMem.Expires__c;
oCMs.OwnerId = accMem.OwnerId;
}
cntMembers.add(oCMs);
System.Debug('Step3 ' + y);
}
System.Debug('Step4 ' + y + 'x is ' + x);
if(y==100){
update cntMembers;
cntMembers.clear();}
}
}