-2

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.

  • 1
    This question is very broad. Can you be more specific about what you are aiming to do and what you've tried? Virtually all data in some Salesforce databases could be PII. – David Reed Nov 11 at 16:57
  • We are trying to remove email & phone. Just changing it at the @ to something else. Then we are changing the phone numbers. – Joshua Anderson Nov 18 at 20:04
0

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 finish(). 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.

  • Thanks David! I will look into this and see what I can do. I was at a loss of where to start and this should put me on the right track. – Joshua Anderson Nov 20 at 7:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.