How to Delete All Debug Apex logs
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty{ margin-bottom:0;
}
up vote
2
down vote
favorite
I'm trying to delete the complete Apex debug logs but getting DML operation Delete not allowed on List<ApexLog>
.
Code:
List <Apexlog> loglist = [Select Id from Apexlog];
delete loglist;
Please provide an idea to delete complete debug logs in code.
debug-logs
add a comment |
up vote
2
down vote
favorite
I'm trying to delete the complete Apex debug logs but getting DML operation Delete not allowed on List<ApexLog>
.
Code:
List <Apexlog> loglist = [Select Id from Apexlog];
delete loglist;
Please provide an idea to delete complete debug logs in code.
debug-logs
1
Possible duplicate of Delete all in Debug log
– Morgan Marchese
2 days ago
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I'm trying to delete the complete Apex debug logs but getting DML operation Delete not allowed on List<ApexLog>
.
Code:
List <Apexlog> loglist = [Select Id from Apexlog];
delete loglist;
Please provide an idea to delete complete debug logs in code.
debug-logs
I'm trying to delete the complete Apex debug logs but getting DML operation Delete not allowed on List<ApexLog>
.
Code:
List <Apexlog> loglist = [Select Id from Apexlog];
delete loglist;
Please provide an idea to delete complete debug logs in code.
debug-logs
debug-logs
edited 2 days ago
David Reed
25.2k51644
25.2k51644
asked 2 days ago
Issac Pal
125
125
1
Possible duplicate of Delete all in Debug log
– Morgan Marchese
2 days ago
add a comment |
1
Possible duplicate of Delete all in Debug log
– Morgan Marchese
2 days ago
1
1
Possible duplicate of Delete all in Debug log
– Morgan Marchese
2 days ago
Possible duplicate of Delete all in Debug log
– Morgan Marchese
2 days ago
add a comment |
2 Answers
2
active
oldest
votes
up vote
5
down vote
You cannot delete the debug logs natively in Apex code. But you can use Rest DELETE endpoint to delete debug logs.
I have created a utility code to delete debug logs that way, you can refer it.
The only limitation is
- It can delete only 100 in 1 iteration(You can use composite API to bulkify it)
It creates a new debug log after execution
List <Apexlog> loglist = [Select Id from Apexlog limit 100];
for(Apexlog al: loglist){
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint(Url.getOrgDomainUrl().toExternalForm()
+ '/services/data/v44.0/sobjects/Apexlog/'+al.Id);
req.setMethod('DELETE');
req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionId());
HttpResponse res = h.send(req);
System.debug(res.getStatusCode());
}
System.debug('loglist'+loglist);
If you are calling this method from lightning component, your Session ID wont be api enabled. Thus you have to use named credentials .
Src: https://salesforce.stackexchange.com/a/183692/19118
2
Nice, that is a useful bit of code.
– David Reed
2 days ago
Yeah, its quite handy when your org creates 100'smb of debug log a minute.
– Pranay Jaiswal
2 days ago
1
Nice Solution! Note that this works only if you're not in a Lightning context, since Lightning Session IDs would not be API-enabled.
– Sebastian Kessel
2 days ago
Yups, in lightning, one needs to use Named credentials. salesforce.stackexchange.com/a/183692/19118
– Pranay Jaiswal
2 days ago
add a comment |
up vote
1
down vote
As far as I can tell, the documentation is mistaken in showing that ApexLog
can be deleted from Apex DML.
The object is deletable from the Tooling API, however. You can tackle this in two ways:
You can actually call out to the Tooling API from your Apex code to perform a delete operation on the object. You would make a
DELETE
method callout to the REST endpoint
/services/data/v43.0/tooling/sobjects/ApexLog/YOUR_LOG_ID
You can do it directly from the Developer Console, without writing a line of code. Simply write
SELECT Id FROM ApexLog
in the Query Editor, check "Use Tooling API", and execute the query. Then, select rows in the results display, and click the Delete Rows button to remove them.
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
You cannot delete the debug logs natively in Apex code. But you can use Rest DELETE endpoint to delete debug logs.
I have created a utility code to delete debug logs that way, you can refer it.
The only limitation is
- It can delete only 100 in 1 iteration(You can use composite API to bulkify it)
It creates a new debug log after execution
List <Apexlog> loglist = [Select Id from Apexlog limit 100];
for(Apexlog al: loglist){
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint(Url.getOrgDomainUrl().toExternalForm()
+ '/services/data/v44.0/sobjects/Apexlog/'+al.Id);
req.setMethod('DELETE');
req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionId());
HttpResponse res = h.send(req);
System.debug(res.getStatusCode());
}
System.debug('loglist'+loglist);
If you are calling this method from lightning component, your Session ID wont be api enabled. Thus you have to use named credentials .
Src: https://salesforce.stackexchange.com/a/183692/19118
2
Nice, that is a useful bit of code.
– David Reed
2 days ago
Yeah, its quite handy when your org creates 100'smb of debug log a minute.
– Pranay Jaiswal
2 days ago
1
Nice Solution! Note that this works only if you're not in a Lightning context, since Lightning Session IDs would not be API-enabled.
– Sebastian Kessel
2 days ago
Yups, in lightning, one needs to use Named credentials. salesforce.stackexchange.com/a/183692/19118
– Pranay Jaiswal
2 days ago
add a comment |
up vote
5
down vote
You cannot delete the debug logs natively in Apex code. But you can use Rest DELETE endpoint to delete debug logs.
I have created a utility code to delete debug logs that way, you can refer it.
The only limitation is
- It can delete only 100 in 1 iteration(You can use composite API to bulkify it)
It creates a new debug log after execution
List <Apexlog> loglist = [Select Id from Apexlog limit 100];
for(Apexlog al: loglist){
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint(Url.getOrgDomainUrl().toExternalForm()
+ '/services/data/v44.0/sobjects/Apexlog/'+al.Id);
req.setMethod('DELETE');
req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionId());
HttpResponse res = h.send(req);
System.debug(res.getStatusCode());
}
System.debug('loglist'+loglist);
If you are calling this method from lightning component, your Session ID wont be api enabled. Thus you have to use named credentials .
Src: https://salesforce.stackexchange.com/a/183692/19118
2
Nice, that is a useful bit of code.
– David Reed
2 days ago
Yeah, its quite handy when your org creates 100'smb of debug log a minute.
– Pranay Jaiswal
2 days ago
1
Nice Solution! Note that this works only if you're not in a Lightning context, since Lightning Session IDs would not be API-enabled.
– Sebastian Kessel
2 days ago
Yups, in lightning, one needs to use Named credentials. salesforce.stackexchange.com/a/183692/19118
– Pranay Jaiswal
2 days ago
add a comment |
up vote
5
down vote
up vote
5
down vote
You cannot delete the debug logs natively in Apex code. But you can use Rest DELETE endpoint to delete debug logs.
I have created a utility code to delete debug logs that way, you can refer it.
The only limitation is
- It can delete only 100 in 1 iteration(You can use composite API to bulkify it)
It creates a new debug log after execution
List <Apexlog> loglist = [Select Id from Apexlog limit 100];
for(Apexlog al: loglist){
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint(Url.getOrgDomainUrl().toExternalForm()
+ '/services/data/v44.0/sobjects/Apexlog/'+al.Id);
req.setMethod('DELETE');
req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionId());
HttpResponse res = h.send(req);
System.debug(res.getStatusCode());
}
System.debug('loglist'+loglist);
If you are calling this method from lightning component, your Session ID wont be api enabled. Thus you have to use named credentials .
Src: https://salesforce.stackexchange.com/a/183692/19118
You cannot delete the debug logs natively in Apex code. But you can use Rest DELETE endpoint to delete debug logs.
I have created a utility code to delete debug logs that way, you can refer it.
The only limitation is
- It can delete only 100 in 1 iteration(You can use composite API to bulkify it)
It creates a new debug log after execution
List <Apexlog> loglist = [Select Id from Apexlog limit 100];
for(Apexlog al: loglist){
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint(Url.getOrgDomainUrl().toExternalForm()
+ '/services/data/v44.0/sobjects/Apexlog/'+al.Id);
req.setMethod('DELETE');
req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionId());
HttpResponse res = h.send(req);
System.debug(res.getStatusCode());
}
System.debug('loglist'+loglist);
If you are calling this method from lightning component, your Session ID wont be api enabled. Thus you have to use named credentials .
Src: https://salesforce.stackexchange.com/a/183692/19118
edited 2 days ago
answered 2 days ago
Pranay Jaiswal
10.6k31950
10.6k31950
2
Nice, that is a useful bit of code.
– David Reed
2 days ago
Yeah, its quite handy when your org creates 100'smb of debug log a minute.
– Pranay Jaiswal
2 days ago
1
Nice Solution! Note that this works only if you're not in a Lightning context, since Lightning Session IDs would not be API-enabled.
– Sebastian Kessel
2 days ago
Yups, in lightning, one needs to use Named credentials. salesforce.stackexchange.com/a/183692/19118
– Pranay Jaiswal
2 days ago
add a comment |
2
Nice, that is a useful bit of code.
– David Reed
2 days ago
Yeah, its quite handy when your org creates 100'smb of debug log a minute.
– Pranay Jaiswal
2 days ago
1
Nice Solution! Note that this works only if you're not in a Lightning context, since Lightning Session IDs would not be API-enabled.
– Sebastian Kessel
2 days ago
Yups, in lightning, one needs to use Named credentials. salesforce.stackexchange.com/a/183692/19118
– Pranay Jaiswal
2 days ago
2
2
Nice, that is a useful bit of code.
– David Reed
2 days ago
Nice, that is a useful bit of code.
– David Reed
2 days ago
Yeah, its quite handy when your org creates 100'smb of debug log a minute.
– Pranay Jaiswal
2 days ago
Yeah, its quite handy when your org creates 100'smb of debug log a minute.
– Pranay Jaiswal
2 days ago
1
1
Nice Solution! Note that this works only if you're not in a Lightning context, since Lightning Session IDs would not be API-enabled.
– Sebastian Kessel
2 days ago
Nice Solution! Note that this works only if you're not in a Lightning context, since Lightning Session IDs would not be API-enabled.
– Sebastian Kessel
2 days ago
Yups, in lightning, one needs to use Named credentials. salesforce.stackexchange.com/a/183692/19118
– Pranay Jaiswal
2 days ago
Yups, in lightning, one needs to use Named credentials. salesforce.stackexchange.com/a/183692/19118
– Pranay Jaiswal
2 days ago
add a comment |
up vote
1
down vote
As far as I can tell, the documentation is mistaken in showing that ApexLog
can be deleted from Apex DML.
The object is deletable from the Tooling API, however. You can tackle this in two ways:
You can actually call out to the Tooling API from your Apex code to perform a delete operation on the object. You would make a
DELETE
method callout to the REST endpoint
/services/data/v43.0/tooling/sobjects/ApexLog/YOUR_LOG_ID
You can do it directly from the Developer Console, without writing a line of code. Simply write
SELECT Id FROM ApexLog
in the Query Editor, check "Use Tooling API", and execute the query. Then, select rows in the results display, and click the Delete Rows button to remove them.
add a comment |
up vote
1
down vote
As far as I can tell, the documentation is mistaken in showing that ApexLog
can be deleted from Apex DML.
The object is deletable from the Tooling API, however. You can tackle this in two ways:
You can actually call out to the Tooling API from your Apex code to perform a delete operation on the object. You would make a
DELETE
method callout to the REST endpoint
/services/data/v43.0/tooling/sobjects/ApexLog/YOUR_LOG_ID
You can do it directly from the Developer Console, without writing a line of code. Simply write
SELECT Id FROM ApexLog
in the Query Editor, check "Use Tooling API", and execute the query. Then, select rows in the results display, and click the Delete Rows button to remove them.
add a comment |
up vote
1
down vote
up vote
1
down vote
As far as I can tell, the documentation is mistaken in showing that ApexLog
can be deleted from Apex DML.
The object is deletable from the Tooling API, however. You can tackle this in two ways:
You can actually call out to the Tooling API from your Apex code to perform a delete operation on the object. You would make a
DELETE
method callout to the REST endpoint
/services/data/v43.0/tooling/sobjects/ApexLog/YOUR_LOG_ID
You can do it directly from the Developer Console, without writing a line of code. Simply write
SELECT Id FROM ApexLog
in the Query Editor, check "Use Tooling API", and execute the query. Then, select rows in the results display, and click the Delete Rows button to remove them.
As far as I can tell, the documentation is mistaken in showing that ApexLog
can be deleted from Apex DML.
The object is deletable from the Tooling API, however. You can tackle this in two ways:
You can actually call out to the Tooling API from your Apex code to perform a delete operation on the object. You would make a
DELETE
method callout to the REST endpoint
/services/data/v43.0/tooling/sobjects/ApexLog/YOUR_LOG_ID
You can do it directly from the Developer Console, without writing a line of code. Simply write
SELECT Id FROM ApexLog
in the Query Editor, check "Use Tooling API", and execute the query. Then, select rows in the results display, and click the Delete Rows button to remove them.
answered 2 days ago
David Reed
25.2k51644
25.2k51644
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f239636%2fhow-to-delete-all-debug-apex-logs%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Possible duplicate of Delete all in Debug log
– Morgan Marchese
2 days ago