You need to sign in to do that
Don't have an account?
Anonymous Developer
Scheduler:
so the logic is when you create a new contact stage the contact Id must be an existing Id on contact. the update happens when the contact staging record is created and the batch is running.
if the fields on contact staging are not equal to null it updates and if the fields are null nothing will happen. does that make sense? Need Help. Thanks
Need help on creating a scheduled batch
Need help creating a scheduled batch class here is my code.
APEX CLASS:
global class AS_UpdateContactFromStagingObject implements Database.Batchable<sObject> { global Database.QueryLocator start(Database.BatchableContext BC){ String query = 'SELECT AS_Contact_Id__c, AS_Date_of_Birth__c, AS_Vaccination_status__c , AS_Safe_to_use_this_phone_number__c, AS_State_Province__c FROM Contact_Staging__c WHERE AS_Agency_Referral__c = True AND AS_Contact_Updated__c = False'; return Database.getQueryLocator(query); } global void execute(Database.BatchableContext BC, List<Contact_Staging__c> batch) { System.debug('batch=='+batch); List<Contact_Staging__c> conList = new List<Contact_Staging__c>(); for(Contact_Staging__c a : batch){ a.AS_Contact_Updated__c = true; conList.add(a); } update conList; } global void finish(Database.BatchableContext BC){ } }
Scheduler:
global class AS_UpdateContactFromStagingSchedulable implements Schedulable { public static String sched = '0 00 00 * * ?'; global static String scheduleBatch() { AS_UpdateContactFromStagingSchedulable SC = new AS_UpdateContactFromStagingSchedulable(); return System.schedule('Update Contact Records', sched, SC); } global void execute(SchedulableContext sc) { AS_UpdateContactFromStagingObject batch = new AS_UpdateContactFromStagingObject(); Database.executeBatch(batch, 50); } }
so the logic is when you create a new contact stage the contact Id must be an existing Id on contact. the update happens when the contact staging record is created and the batch is running.
if the fields on contact staging are not equal to null it updates and if the fields are null nothing will happen. does that make sense? Need Help. Thanks
Can you try the below code for batch class.
In my code I copied AS_Date_of_Birth__c field from stagging object to Birthdate on contact object.
In the similar way you have to add the other columns and map them. Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,
All Answers
Is AS_Contact_Id__c field a contact id field which gets populated on contact staging record?
So you want tha batch to copy the fields from Contact staging to contact and update those fields if the value is not null.
Thanks,
Yes this logic need to be implemented in our personal org as these are custom objects it takes time to implement the logic. Please allow some time to answer this.
Thanks,
but I have no clue on how to implement it through code. Thanks
Can you try the below code for batch class.
In my code I copied AS_Date_of_Birth__c field from stagging object to Birthdate on contact object.
In the similar way you have to add the other columns and map them. Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,
Is the issue resolved now?
Thanks,