
global void execute(Database.BatchableContext BC, List<Opportunity> scope){
List<Opportunity> dealsToUpdate = new List<Opportunity>();
for(Opportunity j : [Select Id, OwnerId, Name, CloseDate,Account.OwnerId, Account.Id,Account.Owner.IsActive,Account.Active__c, Account.Name, Account.GMF_ACF__c from Opportunity where stagename != 'DECLINE,WITHDRW' and Account.recordtypeid = :ActRecTypeID and account.owner.House_Account__c = false and account.owner.isActive = true and Account.LastModifiedDate = Last_Month and Account.LastModifiedById = :wendy and Account.Active__c = 'Y' limit 20000])
{
if(j.OwnerID != account.OwnerID){
Opportunity mOpportunity = new Opportunity();
mOpportunity.Id = j.Id;
mOpportunity.OwnerID = account.OwnerID;
dealsToUpdate.add(mOpportunity);
}
/*Account a = (Account)obj;
Opportunity o;
Account a;*/
//for(Opportunity o: j.opportunities){
/*if(o.OwnerID != j.OwnerID){
Opportunity mOpportunity = new Opportunity();
mOpportunity.Id = o.Id;
mOpportunity.OwnerID = j.OwnerID;
dealsToUpdate.add(mOpportunity);
}*/
//}
}
if(dealsToUpdate.size()>0)
{
update dealsToUpdate;
}
}
1 个回答
Jonathan,
Account is a field of your Opportunity j : you should refer to j.Account.OwnerId.For example :
if(j.OwnerID != j.account.OwnerID){
I hope that helps.
Rupert