How to Delete All Debug Apex logs





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty{ margin-bottom:0;
}






up vote
2
down vote

favorite
1












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.










share|improve this question




















  • 2




    Possible duplicate of Delete all in Debug log
    – Morgan Marchese
    Nov 16 at 16:35

















up vote
2
down vote

favorite
1












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.










share|improve this question




















  • 2




    Possible duplicate of Delete all in Debug log
    – Morgan Marchese
    Nov 16 at 16:35













up vote
2
down vote

favorite
1









up vote
2
down vote

favorite
1






1





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.










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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














  • 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










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




  1. It can delete only 100 in 1 iteration(You can use composite API to bulkify it)


  2. 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






share|improve this answer



















  • 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


















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:





  1. 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




  2. 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.







share|improve this answer





















    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "459"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    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

























    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




    1. It can delete only 100 in 1 iteration(You can use composite API to bulkify it)


    2. 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






    share|improve this answer



















    • 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















    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




    1. It can delete only 100 in 1 iteration(You can use composite API to bulkify it)


    2. 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






    share|improve this answer



















    • 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













    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




    1. It can delete only 100 in 1 iteration(You can use composite API to bulkify it)


    2. 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






    share|improve this answer














    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




    1. It can delete only 100 in 1 iteration(You can use composite API to bulkify it)


    2. 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







    share|improve this answer














    share|improve this answer



    share|improve this answer








    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














    • 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












    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:





    1. 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




    2. 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.







    share|improve this answer

























      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:





      1. 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




      2. 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.







      share|improve this answer























        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:





        1. 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




        2. 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.







        share|improve this answer












        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:





        1. 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




        2. 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.








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 16 at 16:04









        David Reed

        25.7k51644




        25.7k51644






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            AnyDesk - Fatal Program Failure

            How to calibrate 16:9 built-in touch-screen to a 4:3 resolution?

            QoS: MAC-Priority for clients behind a repeater