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
2
Possible duplicate of Delete all in Debug log
– Morgan Marchese
Nov 16 at 16:35
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 Nov 16 at 15:47
David Reed
25.7k51644
25.7k51644
asked Nov 16 at 15:42
Issac Pal
125
125
2
Possible duplicate of Delete all in Debug log
– Morgan Marchese
Nov 16 at 16:35
add a comment |
2
Possible duplicate of Delete all in Debug log
– Morgan Marchese
Nov 16 at 16:35
2
2
Possible duplicate of Delete all in Debug log
– Morgan Marchese
Nov 16 at 16:35
Possible duplicate of Delete all in Debug log
– Morgan Marchese
Nov 16 at 16:35
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
Nov 16 at 16:05
Yeah, its quite handy when your org creates 100'smb of debug log a minute.
– Pranay Jaiswal
Nov 16 at 16:11
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
Nov 16 at 16:18
Yups, in lightning, one needs to use Named credentials. salesforce.stackexchange.com/a/183692/19118
– Pranay Jaiswal
Nov 16 at 16:24
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
Nov 16 at 16:05
Yeah, its quite handy when your org creates 100'smb of debug log a minute.
– Pranay Jaiswal
Nov 16 at 16:11
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
Nov 16 at 16:18
Yups, in lightning, one needs to use Named credentials. salesforce.stackexchange.com/a/183692/19118
– Pranay Jaiswal
Nov 16 at 16:24
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
Nov 16 at 16:05
Yeah, its quite handy when your org creates 100'smb of debug log a minute.
– Pranay Jaiswal
Nov 16 at 16:11
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
Nov 16 at 16:18
Yups, in lightning, one needs to use Named credentials. salesforce.stackexchange.com/a/183692/19118
– Pranay Jaiswal
Nov 16 at 16:24
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 Nov 16 at 16:25
answered Nov 16 at 16:04
Pranay Jaiswal
10.7k31950
10.7k31950
2
Nice, that is a useful bit of code.
– David Reed
Nov 16 at 16:05
Yeah, its quite handy when your org creates 100'smb of debug log a minute.
– Pranay Jaiswal
Nov 16 at 16:11
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
Nov 16 at 16:18
Yups, in lightning, one needs to use Named credentials. salesforce.stackexchange.com/a/183692/19118
– Pranay Jaiswal
Nov 16 at 16:24
add a comment |
2
Nice, that is a useful bit of code.
– David Reed
Nov 16 at 16:05
Yeah, its quite handy when your org creates 100'smb of debug log a minute.
– Pranay Jaiswal
Nov 16 at 16:11
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
Nov 16 at 16:18
Yups, in lightning, one needs to use Named credentials. salesforce.stackexchange.com/a/183692/19118
– Pranay Jaiswal
Nov 16 at 16:24
2
2
Nice, that is a useful bit of code.
– David Reed
Nov 16 at 16:05
Nice, that is a useful bit of code.
– David Reed
Nov 16 at 16:05
Yeah, its quite handy when your org creates 100'smb of debug log a minute.
– Pranay Jaiswal
Nov 16 at 16:11
Yeah, its quite handy when your org creates 100'smb of debug log a minute.
– Pranay Jaiswal
Nov 16 at 16:11
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
Nov 16 at 16:18
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
Nov 16 at 16:18
Yups, in lightning, one needs to use Named credentials. salesforce.stackexchange.com/a/183692/19118
– Pranay Jaiswal
Nov 16 at 16:24
Yups, in lightning, one needs to use Named credentials. salesforce.stackexchange.com/a/183692/19118
– Pranay Jaiswal
Nov 16 at 16:24
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 Nov 16 at 16:04
David Reed
25.7k51644
25.7k51644
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
2
Possible duplicate of Delete all in Debug log
– Morgan Marchese
Nov 16 at 16:35