function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sukhdeep SinghSukhdeep Singh 

I need to write a script to trigger the sync for all records for all the tables being sync

I need to write a script to trigger the sync for all records for all the tables being sync over to some other database say My SQL database.
This class will query all accounts, contacts, Opportunities, User, and so on… all the objects that we sync from SFDC to MySQL.
For this, I just need to query in batch mode, update the name or some other column that would trigger all outbound messages and then update the records back to original state.

I have a sample class below which edits all contacts with a specific extension.
But How I can I modify it to edit records for all objects So that it trigers my all outbound messages
and then update the records back to original state.

global class BatchUpdateDataSync implements Database.Batchable<Sobject> {
  global final List<Account> accLst=new List<Account>();
  global final List<Contact> conLst=new List<Contact>();
  global final String value;
  global BatchUpdateDataSync(string sandbox) {
    value = sandbox;
  }
  global Database.QueryLocator start(Database.BatchableContext BC) {
// query for contacts only How I can pass query for all other objects ?
    return Database.getQueryLocator([Select c.Id,c.Email from Contact c]);
  }
  global void execute(Database.BatchableContext BC, List<Contact> records) {
    for(Contact con:records){
     if(con.Email!=Null){
      con.Email=con.Email+'.'+value;
         conLst.add(con);
     }   
    }
    if(conLst.size()>0) update conLst;
// Where I need to write code to revert changes ?
  }
  global void finish(Database.BatchableContext BC) {
  }
}