You need to sign in to do that
Don't have an account?
Scheduled Batch Need Help
- I want to get all the records where the field agency referral is true and the field contact update = false
- I want to update contact records based on records info
- and update contact update = false
This is the code that I have for now since I'm stuck and need help.
Apex class:
global class UpdateContactFromStagingObject implements Database.Batchable<sObject> {
List<Contact> conList = new List<Contact>();
global Database.QueryLocator start(Database.BatchableContext BC){
String query = 'SELECT AS_Contact_Id__c FROM Contact_Staging__c WHERE AS_Agency_Referral__c = True AND Contact_Updated__c = False';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<Contact> batch) {
System.debug('batch=='+batch);
Set<String> conId = new Set<String>();
for(Contact_Staging__c a : batch){
conId.add(a.AS_Contact_Id__c);
}
}
global void finish(Database.BatchableContext BC){
}
}
Scheduled Batch Class:
global class UpdateContactFromStagingObjectSchedulable implements Schedulable {
public static String sched = '0 00 05 * * ?';
global static String scheduleMe() {
UpdateContactFromStagingObjectSchedulable SC = new UpdateContactFromStagingObjectSchedulable();
return System.schedule('Update Contact Records', sched, SC);
}
global void execute(SchedulableContext sc) {
UpdateContactFromStagingObject batch = new UpdateContactFromStagingObject();
Database.executeBatch(batch, 200);
}
}
Is there anything I need to add? Thanks.
Please check the below batch class.
Schedular;
You can schdule this schedular as below in required time through UI.
You can go to Setup > Build > Develop > Apex Classes and then press on the Schedule Apex button
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,
All Answers
Can you let us know what you are trying to update on Contact_Staging__c object. Are you trying to update any field? If so can you let us know which field you want to update because there is not logic for updation of field in the batch.
Also can you let us know when do you want to schedule the class to run?
Thanks,
Which fields you want to update on contact records due to batch proecss
Hello Sai and Mukesh
Any field be it name or Id or status
Please check the below batch class.
Schedular;
You can schdule this schedular as below in required time through UI.
You can go to Setup > Build > Develop > Apex Classes and then press on the Schedule Apex button
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,
Hey Sai what if when I create a contact staging I want it to mirror the update on my contacts and it only updates the fields that have been filed or ticked and the fields that are not filed are not updated how would that look?
this is the contact staging so it only updates when the contact Id is the same contact Id as the contact? does that make sense?
Hi Hammad,
I could not understand your ask. I am not sure how the batch which we wrote it related to that UI.
Thanks,
Hi Sai
What I mean to ask is that I want to create a batch that can update the contact staging.
If the contact Id on contact staging exists on contacts it updates only the fields that have a value when creating the contact staging on this picture
So if the text area or picklist or checkbox is empty it will not update the contacts but if it's not empty the contact staging updates.