Masking policies target objects: Account, Contact, Lead, Case. Debug logs sit outside that scope entirely, and they routinely capture the exact same real names, emails, and phone numbers that your masking job was supposed to eliminate. A developer runs a trace flag against production before a refresh, the ApexLog records every System.debug() statement verbatim, and that log survives in the sandbox long after the refresh completes. Nobody masked it, because nobody thought to look.
This isn't a theoretical gap. It's a routine side effect of how Salesforce developers debug things, and it happens in nearly every org that does serious Apex or integration work.
What a debug log actually contains
A Salesforce debug log is a flat text record of everything that happened during a transaction: SOQL queries, trigger execution, callout payloads, and any System.debug() output a developer added. If a query pulls Contact.Email or Lead.Phone into a variable and a debug statement prints that variable, the raw value lands in the log file.
Callout logs are worse. Integration code frequently logs the full request and response body for troubleshooting, which means an outbound payload to a payment processor or an inbound response from a marketing platform can sit in an ApexLog with card-adjacent data, order details, and customer identifiers fully intact.
These logs are stored as ApexLog records, accessible through Setup, the Developer Console, or the Tooling API. They are not custom objects your masking tool scans. They don't show up in a data model diagram. They're metadata, and most masking platforms were built to rewrite field values on records, not to parse free-text log bodies.
Why masking tools walk right past this
Field-level masking works by identifying a target object, a target field, and a replacement strategy. It operates on structured data with a known schema. Debug logs have no schema worth mentioning. They're unstructured text blobs that vary wildly in length and content from one trace to the next.
Even a masking tool that is excellent at anonymizing Contact and Case data has no mechanism for scanning ApexLog bodies for PII patterns unless that capability was built in deliberately. Most weren't. The vendors building generic data masking tools for CRMs are optimizing for the 20 standard and custom objects that hold 95% of structured PII, and debug logs never made that list.
Add to that the fact that logs are often generated after the refresh and mask job run, not before. A QA engineer enables a trace flag on day three of the sandbox's life to chase a bug, and that trace flag pulls live-looking data straight out of already-masked records combined with whatever test data was entered that week. The log itself was never in scope for any masking pass because it didn't exist yet.
The GDPR exposure window this creates
Article 5(1)(f) of GDPR requires appropriate security against unauthorized processing, and a debug log full of real customer emails sitting in a sandbox that twenty contractors can access doesn't meet that bar. The irony is that the org did the right thing by masking its Contact and Lead records, then undid the protection the moment someone ran a trace.
Debug logs also retain data for a fixed window, typically up to seven days by default, which sounds short until you consider how sandbox refresh cycles work. A partial copy sandbox refreshed monthly can accumulate dozens of trace logs between refreshes, each one a potential snapshot of real customer data that predates or postdates the masking job entirely.
I'd argue this is the quiet version of the free-text field problem. Everyone eventually audits their custom text fields for PII because someone gets burned once. Debug logs don't get that scrutiny because they feel transient and technical, not like customer data at all. That perception is wrong, and it's exactly the kind of gap a DPA auditor loves to find.
Where the leaks actually show up
Four places account for most of the real-world exposure we see in Salesforce orgs that haven't addressed this.
| Source | What leaks | Why it happens |
|---|---|---|
| Trace flags on users | Full record values in SOQL query logs | Admin debugging a user issue traces that user's session |
| Apex callout logging | Full request/response bodies with customer data | Integration code logs payloads for troubleshooting |
| Email service logs | Recipient addresses and message content | Inbound email handlers log message details |
| Flow and Process Builder debug | Field values printed during flow interviews | Admins debug flow logic against real-looking test records |
Each of these generates an ApexLog or equivalent record that lives independently of the object data your masking policy covers. None of them get swept up by a standard mask-before-refresh job.
Closing the gap without slowing development down
The fix isn't to ban debug logs, which would make Salesforce development nearly impossible. It's to treat log retention and access as part of the same compliance boundary as the data itself.
Set a short retention policy on trace flags and let them expire automatically rather than leaving them active indefinitely. Restrict Developer Console and log download access in sandboxes to the same Minimum Necessary principle you'd apply to production, instead of giving every sandbox user broad visibility by default. Audit callout code for System.debug() calls that print full payloads and replace them with calls that log only non-sensitive identifiers, like a record Id instead of an email address.
MaskEzee handles this by masking source data before it ever gets queried, logged, or exposed in a trace, so a debug log generated after refresh captures already-fake values instead of real ones. That doesn't eliminate every risk, since a trace run between refresh and mask completion can still catch a sliver of real data, but it closes the much larger window where logs accumulate real PII across the sandbox's entire lifecycle.
Building log hygiene into your refresh checklist
Most sandbox refresh runbooks list steps like disable outbound emails, run the mask job, reset integration user credentials. Add a line for clearing active trace flags and purging old ApexLog records as part of that same checklist, not as an afterthought handled by whoever happens to notice.
Debug log cleanup takes one Tooling API call or a few clicks in Setup under Debug Logs. It costs nothing in effort and closes a gap that a lot of security reviews never think to check. Given how little it takes, there's no good argument for leaving it out of a standard refresh process.
Treat debug logs the same way you'd treat a database export: something that needs an owner, a retention limit, and an access boundary. Salesforce gives admins the controls to do this. The only missing piece is usually the checklist line that says to use them.
Frequently Asked Questions
Do Salesforce debug logs count as personal data under GDPR?
Yes, if a debug log contains names, emails, phone numbers, or other identifying values pulled from live records, it is personal data under GDPR regardless of where it's stored. The format of the data, whether it's a structured field or a line of text in a log file, does not change its regulatory classification. Controllers are still responsible for protecting it against unauthorized access.
Can masking tools scan debug log content for PII?
Most standard Salesforce data masking tools operate on object fields and do not parse ApexLog text bodies for sensitive patterns. Some advanced platforms can apply pattern matching to log content, but this is not standard behavior across the market. The safer approach is preventing real PII from entering logs in the first place by masking source data before logs get generated.
How long do Salesforce debug logs persist by default?
Debug logs generated by trace flags typically persist for up to seven days before automatic expiration, though this depends on log size limits and org configuration. Logs can also be deleted manually at any point through Setup or the Tooling API. Admins should not assume automatic expiration alone is sufficient and should actively purge logs tied to sensitive debugging sessions.
Who can access debug logs in a Salesforce sandbox?
Access depends on permissions like View All Data, Author Apex, and specific debug log permissions assigned through profiles or permission sets. In many sandboxes these permissions are granted broadly to speed up development, which means far more users can view logs than should have access to sensitive data. Restricting these permissions to only the users who need them reduces the exposure surface significantly.
Does masking data before a sandbox refresh prevent debug log exposure?
Masking source data before refresh significantly reduces risk because any debug log generated afterward will capture already-fake values instead of real ones. It does not eliminate risk entirely, since trace flags active during the window before masking completes can still capture real data. Combining pre-refresh masking with strict trace flag retention policies closes nearly all of the exposure window.