
System.debug('WORKING!!!!!!*********');
String ActRecTypeID = [SELECT Name, Id, DeveloperName, SobjectType FROM RecordType where SobjectType = 'Account' and Name = 'Activated'].Id;
//Sandbox Record Type ID = 01230000000DD54AAG
List<Integer> contactCount = new List<Integer>();
Integer iSize = 0 ;
List<Account> accountWithContacts = [SELECT OwnerId, Id, owner.isActive, Active__c, Name, account.GMF_ACF__c, (SELECT Id,OwnerId,Name FROM Contacts where end_date__c = null and CreatedDate >= 2008-10-03T00:00:00Z) FROM Account where recordtypeid ='01230000000DD54AAG' and account.owner.House_Account__C = false and owner.isActive = true and LastModifiedDate >= Yesterday and active__c = 'Y' limit 8000];
List<Contact> contactsToUpdate = new List<Contact>();
//For loop to iterate through all queried Account records
for(Account a: accountWithContacts){
//Use the child relationships dot syntax to accesss the related
for(Contact c: a.Contacts){
if(c.OwnerID != a.OwnerID){
c.OwnerID = a.OwnerID;
// Contact updCont = [Select ownerID from Contact where id = :c.id];
//updCont.ownerid = a.ownerid;
System.debug('Contact Id['+ c.Id +'], Name['+ c.name +']');
contactsToUpdate.add(c);
contactCount.add(1);
iSize++;
//if(iSize == 200){
update contactsToUpdate;
System.debug('********UPDATE COUNT: ' + iSize);
iSize = 0;
//}
}
}
}
update contactsToUpdate;
if(iSize > 0){
update contactsToUpdate;
}
}
2 risposte
Jonathan,
I think the best way you should go ahead with a batch Approach.
Split it into two Queries... and then continue