You need to sign in to do that
Don't have an account?

How to fetch and delete records before 30m as per shcedule time
Hi,
I have two objects doctor, appointment and there is a lookup relationship between them. have a fields called appointment_date__c(date/time type) and doctor__c lookup field in Appointment.
Now i have to delete the Appointment records those are Schedule is 'Confirm'(Doctor object field) and current time is 30m before from appointment_date__c field time.
for suppose 5 records appointment time is 6:30PM and current time is 6:00PM, this 5 records have to fetch and delete.
My Batch Class:
Global class AppointmentDelete implements database.Batchable<sObject>{
global database.QueryLocator start(database.BatchableContext BC){
string c='Confirm';
String query='Select id,Name, doctor__r.name from Appointment__C where doctor__r.Schedule__c =\'' + c + '\'';
system.debug('>>>>>>>query: '+query);
return database.getQueryLocator(query);
}
global Void execute(database.BatchableContext BC, List<Appointment__C> scope ){
delete scope;
}
global void finish(database.BatchableContext BC){
}
}
I have two objects doctor, appointment and there is a lookup relationship between them. have a fields called appointment_date__c(date/time type) and doctor__c lookup field in Appointment.
Now i have to delete the Appointment records those are Schedule is 'Confirm'(Doctor object field) and current time is 30m before from appointment_date__c field time.
for suppose 5 records appointment time is 6:30PM and current time is 6:00PM, this 5 records have to fetch and delete.
My Batch Class:
Global class AppointmentDelete implements database.Batchable<sObject>{
global database.QueryLocator start(database.BatchableContext BC){
string c='Confirm';
String query='Select id,Name, doctor__r.name from Appointment__C where doctor__r.Schedule__c =\'' + c + '\'';
system.debug('>>>>>>>query: '+query);
return database.getQueryLocator(query);
}
global Void execute(database.BatchableContext BC, List<Appointment__C> scope ){
delete scope;
}
global void finish(database.BatchableContext BC){
}
}
Hi,
Datetime d = datetime.now().addMinutes(-30);
Datetime dnow = datetime.now();
String query='Select id,Name, doctor__r.name from Appointment__C where doctor__r.Schedule__c =\'' + c + '\' AND appointment_date__c <= dnow AND appointment_date__c>=d';
Can you please try to use above soql?