You need to sign in to do that
Don't have an account?
Robbert Bos2
WHERE clause on a date in a for loop
I'm trying to find the fee which is active on the date of the worked hours. Goal is to schedule this every week to see our revenues.
Does anybody know how I can use the where clause in de for loop so the start date of the Fee is smaller (or equal) to the date of the time entry?
Does anybody know how I can use the where clause in de for loop so the start date of the Fee is smaller (or equal) to the date of the time entry?
global class RevenueTimeEntry implements Schedulable { global void execute(SchedulableContext sc) { List<timeEntry__c> TimeEntry = new List<timeEntry__c>( [SELECT Id, date__c FROM timeEntry__c WHERE Fee1__c = null LIMIT 10]); System.debug(TimeEntry); for(timeEntry__c te : TimeEntry){ Decimal fee = [ SELECT Fee2__c FROM AssignmentFee__c //WHERE DateStart__c <= :TimeEntry.date__c LIMIT 1].Fee2__c; te.Fee1__c = fee; } update TimeEntry; } }
All Answers
It is a best practice to avoid soql query inside the for loop.
Please check the below code. Thanks,
Nagendra