What architectural components make up a robust integration logging and auditing framework in Salesforce?
Answer
Basics: When an integration fails at 2 a.m., you need to know what was sent, what came back and which record it concerned. Debug logs are short-lived (24 hours, 20 MB per log) and not designed for this, so teams build their own logger and store entries as records.
How it works (components):
- Log object:
Integration_Log__cwith Correlation_Id, Direction (Inbound/Outbound), Endpoint or Named Credential, HTTP method, Status code, Status picklist (Success, Failed, Retry), Duration, Related Record Id, Attempt count, Request and Response (long text, up to 131,072 characters, truncated and masked). - Logger service: an Apex class that buffers entries in memory and flushes once.
- Wrapper around callouts and inbound Apex REST handlers so logging is automatic.
- Alerting: Flow or platform event on failures; dashboards for error rate and latency.
- Retention: scheduled batch to delete or archive old logs.
Advanced / deep dive: Transaction behavior is the key design issue. Inserting a log before a callout causes "uncommitted work pending", so buffer and flush after callouts. If the transaction fails and rolls back, so does the log; use a platform event published immediately (with a trigger that inserts the log) or log from a finalizer or separate async job. Volume: millions of rows cost storage, so log failures at full detail and successes sparsely (a custom metadata log-level switch), or use Big Objects or external tools (Splunk, Datadog) via events. Security: never log Authorization headers, tokens or sensitive personal data; mask fields and consider Shield Platform Encryption for log fields. Pass a correlation ID header to the remote system so end-to-end tracing works. Add Event Monitoring (Shield) for API-level audit of who called what.
Code / config example: