I am working on a batch and am writing a query but am getting confused because of the relationship... The batch is written on a junction object, Account_BOB__c, between 2 parents Account & Book_Of_Business__c. When an Account_BOB__c is created, a field on Account is updated, based upon the fields on Book_Of_Business. I'm currently working through the logic of execute method but I have confused myself. Here is my code thus far:
global class Batch implements Database.Batchable<sObject>, Database.Stateful, Schedulable {
global String query = 'SELECT Id, Account__c, Book_of_Business__c, Status__c, Book_of_Business__r.Level__c, Book_of_Business__r.Relationship_Owner__c FROM Account_BOB__c ' +
'WHERE Status__c = Active' +
'AND Effective_Date__c = TODAY';
public Database.QueryLocator start(Database.BatchableContext BC) {
return Database.getQueryLocator(query);
}
public void execute(Database.BatchableContext BC, List<Account_BOB__c> scope) {
Set<Id> accBOBIdSet = new Set<Id>();
Map<Id, Account> accByAccBOBIdMap = new Map<Id, Account>();
for(Account_BOB__c accBOB : scope) {
accBOBIdSet.add(accBOB.Id);
}
for(Book_of_Business__c bob : [SELECT Id FROM Book_of_Business__c WHERE Account_BOB__c IN :accBOBIdSet])
The error is coming on the last line. Because there is no Account_BOB__c on Book_Of_Business__c.
I am trying to get the Book_Of_Business fields associated with each Account BOB in my scope. But not sure how to do that in my WHERE
because this object being on the child side of the relationship.
I'm sorry if I explained this incorrectly, but does anyone have any ideas?
Thanks!