Is there a best practice for writing a script to run and remove all PII in an org? I am trying to remove email addresses & phone numbers from all objects and replace them with dummy data. Would we need to call out every object individually or would we be able to write something that says if field type is email then replace? Not sure what the best practice of this would be so trying to figure out where to start.
I believe you mean "Anonymous window" rather than "asynchronous window". It is unlikely in a sandbox with any substantial amount of data that this route will be the most expeditious. You'll be limited to a single transaction worth of records in each invocation of Anonymous Apex - a maximum of 10,000 DML rows, among other limits. I'd consider this a solution for a small developer sandbox only, although in such a case - where the data is not being copied by the platform - it's probably easier to anonymize the data prior to loading it.
The most natural solution to me, if you're not going to purchase one of the many third-party products offering sandbox seeding and data anonymization, is a chained Apex batch class.
The class would process one sObject each time it runs and then chain itself to process the next sObject desired, in
execute(), you'd walk the describe information for the current sObject and process the phone and email fields across the scope for that batch. (Better still, walk the describe in
start() and cache the data for more speed).
You'd kick it off from Anonymous Apex by passing a
List<String> to the constructor, which the batch would store and pass down the chained invocation until it traverses all of the specified sObjects.
If you're new to Batch Apex, I recommend completing the relevant Trailhead module and searching SFSE for topics like "batch chaining". You'll find lots of prior art and resources.