You need to sign in to do that
Don't have an account?
Anonymous Developer
Need Help on Scheduled Batch
I want to create a batch that can update the contact details if it found a contact record
global class AS_UpdateContactFromStagingObject implements Database.Batchable<sObject> {
global Database.QueryLocator start(Database.BatchableContext BC){
String query = 'SELECT AS_Contact_Id__c, AS_Pronouns__c, AS_Aboriginal_or_Torres_Strait_Islander__c, AS_Date_of_Birth__c, AS_CALD__c, AS_Vaccination_status__c, AS_Require_an_interpreter__c, AS_TIS_Interpreter_Language_Required__c, AS_Safe_to_use_this_phone_number__c, AS_Is_it_safe_to_use_this_email_address__c, AS_Can_a_voicemail_be_left__c, AS_Street__c, AS_City__c, AS_State_Province__c, AS_Zip_Postal_Code__c, AS_Country__c, AS_Why_is_this_their_current_location__c, AS_Agency_Referral__c, AS_Contact_Updated__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_Id__c = '';
a.AS_Pronouns__c = '';
a.AS_Aboriginal_or_Torres_Strait_Islander__c = '';
a.AS_Date_of_Birth__c = '';
a.AS_CALD__c = '';
a.AS_Vaccination_status__c = '';
a.AS_Require_an_interpreter__c = '';
a.AS_TIS_Interpreter_Language_Required__c = '';
a.AS_Safe_to_use_this_phone_number__c = '';
a.AS_Is_it_safe_to_use_this_email_address__c = '';
a.AS_Can_a_voicemail_be_left__c = '';
a.AS_Street__c = '';
a.AS_City__c = '';
a.AS_State_Province__c = '';
a.AS_Zip_Postal_Code__c = '';
a.AS_Country__c = '';
a.AS_Why_is_this_their_current_location__c = '';
a.AS_Agency_Referral__c = False;
a.AS_Contact_Updated__c = True;
conList.add(a);
}
update conList;
}
global void finish(Database.BatchableContext BC){
}
}
- the batch will update the contact record
- will only update the record once
global class AS_UpdateContactFromStagingObject implements Database.Batchable<sObject> {
global Database.QueryLocator start(Database.BatchableContext BC){
String query = 'SELECT AS_Contact_Id__c, AS_Pronouns__c, AS_Aboriginal_or_Torres_Strait_Islander__c, AS_Date_of_Birth__c, AS_CALD__c, AS_Vaccination_status__c, AS_Require_an_interpreter__c, AS_TIS_Interpreter_Language_Required__c, AS_Safe_to_use_this_phone_number__c, AS_Is_it_safe_to_use_this_email_address__c, AS_Can_a_voicemail_be_left__c, AS_Street__c, AS_City__c, AS_State_Province__c, AS_Zip_Postal_Code__c, AS_Country__c, AS_Why_is_this_their_current_location__c, AS_Agency_Referral__c, AS_Contact_Updated__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_Id__c = '';
a.AS_Pronouns__c = '';
a.AS_Aboriginal_or_Torres_Strait_Islander__c = '';
a.AS_Date_of_Birth__c = '';
a.AS_CALD__c = '';
a.AS_Vaccination_status__c = '';
a.AS_Require_an_interpreter__c = '';
a.AS_TIS_Interpreter_Language_Required__c = '';
a.AS_Safe_to_use_this_phone_number__c = '';
a.AS_Is_it_safe_to_use_this_email_address__c = '';
a.AS_Can_a_voicemail_be_left__c = '';
a.AS_Street__c = '';
a.AS_City__c = '';
a.AS_State_Province__c = '';
a.AS_Zip_Postal_Code__c = '';
a.AS_Country__c = '';
a.AS_Why_is_this_their_current_location__c = '';
a.AS_Agency_Referral__c = False;
a.AS_Contact_Updated__c = True;
conList.add(a);
}
update conList;
}
global void finish(Database.BatchableContext BC){
}
}
You can schedule the above the by using salesforce UI.
If this helps, Please mark it as best answer.
Thanks!!
Hi Ankaiah
the scheduled batch is already finished I could not rename the title when it was created
So this is the contact staging i created I want when the batch updates the fields that are filled or checkboxes that are checked are updated on the contact record with the same contact Id on contacts
does it make sense? if it does I need help. THanks