How to generate Debug Logs for Salesforce System User?

How to generate Debug Logs for Salesforce System User?

In order to generate Debug Logs for Salesforce System User, we have to create the TraceFlag for the System User.

If Automate Case User is System and if you would like to generate Debug Logs for Salesforce System User, use the following steps.

1. Get the System User Id using the following SOQL.

SELECT Id
FROM User
WHERE Name = 'System'

2. Get the DebugLevelId using the following SOQL.

SELECT Id, DeveloperName
FROM DebugLevel

3. Do a POST request to create TraceFlag record. This is help to generate Debug Logs for the System user.

Endpoint:

/services/data/v60.0/tooling/sobjects/TraceFlag/

Body:

{ 
	"TracedEntityId" : "0051I000002TGySQAW", 
	"DebugLevelId" : "7dlDF0000008aFSYAY",
	"LogType" : "USER_DEBUG", 
	"StartDate" : "2024-02-20T22:12:00.000+0000",
	"ExpirationDate" : "2024-02-20T22:30:00.000+0000"
}

Leave a Reply