I have a many to many relation. Account obj, AccountAdress junction, Adres obj. The junction object has a startdate an enddate to make an address active for an Account.
I want to use a batch process to update all Accounts with the Adress which is active on the junction.
What would be the most effective soql to achieve this. Do I query from the junction object to get the accounts and adresses and pas them into maps and match them and update. Or do query from account and update if a active adress is found
List<Accounts> accList = [Select id from account];//Batch soql List<Adress> updateAdresses = [SELECT Id, street FROM Adress WHERE Id IN (SELECT Adress FROM AcountAdress WHERE account__c IN : accList ) ];
[SELECT id, startdate, enddate, account__c,addres__c FROM AcountAdress where today>startdate AND today<startdate]; create map for account and loop trough AccountAdress and update with Adress