You need to sign in to do that
Don't have an account?
Luke Higgins 23
Batch Class Error on Execute
I am trying to count the number of placements on each account. I thought about using a trigger and flow to do this but I think there are too many placements for this to work. This batch class I wrote is returning an error that I am uncertain how to get around. "Invalid bind expression type Account for Column of type Id" on line 9
public class plcCounterOnAcct implements Database.Batchable<sObject>, Database.Stateful { public Database.QueryLocator start(Database.BatchableContext bc) { String query = 'SELECT Id, Name FROM Account'; return Database.getQueryLocator(query); } public void execute(Database.BatchableContext BC, List<Account> acctList){ for(Account acc : acctList){ List<ts2__Placement__c> plcOnAcct = [SELECT Id FROM ts2__Placement__c WHERE ts2__Client__c = :acc]; acc.Total_Placement_Count__c = plcOnAcct.size(); } try { // Update the Account Record update acctList; } catch(Exception e) { System.debug(e); } } public void finish(Database.BatchableContext BC){ } }
What does your field "ts2__Client__c " store ? If it has AccountId value in it try changing your line 9 like below:
This will compare if there are any ts2__Placement__c records with field ts2__Client__c having AccountId.
Hope this helps!
Thanks