function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Mikhail ShumenkoMikhail Shumenko 

FIELD_INTEGRITY_EXCEPTION - Trace flags can be active for up to 24 hours. Set ExpirationDate to be less than 24 hours from StartDate, or, if StartDate is null, less than 24 hours from now

Hi,

I try to create my own tool for executing Anonymous Code. For this purpose I'm using Tooling API.
Tooling API classes were generated by force-wsc-35.0.0.jar

For triggering an Apex debug log at the specified logging level I'm using "General" trace flag (LogType = 'DEVELOPER_LOG', DebugLevel = 'SFDC_Console').
Before anonymous code execution I set new value for folowing fields:
(StartDate = <now()>, ExpirationDate = <twoHowrsFromNow()>, DebugLevelId = <sfdcConsoleDebugLevelId>)

In first attempt I have been tried to set StartDate to "null" (I assume that if I will set StartDate to "null" then it implicitly set to <now()>)

But in this case I've got error:

FIELD_INTEGRITY_EXCEPTION - Trace flags can be active for up to 24 hours. Set ExpirationDate to be less than 24 hours from StartDate, or, if StartDate is null,
less than 24 hours from now.: Expiration Date

Then I try to set StartDate to <now()> directly and execute anonymous code again, but no Apex Log have been created.
The next day (and now) it worked fine. Can you explain how to check that when I execute anonymous code, then related log will be created necessary.

Also I have one more question. How to fetch log related to my Anonymous code execution ?
At the moment I forced to use 'fetchLastLogForUser(userId);' logic, with the hope that this is really what I need.

All what I want is a fast way to execute anonymous code and fetch related log.

Also I try to use Apex SOAP API but looks like this approach is deprecated, and I have some troubles with Log Level customization.

Can you advise me what should I do to achieve my goal ?

Best regards, Michael.