Silence the AvoidGlobalModifier warning in @RestResource Apex controller

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





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







up vote
5
down vote

favorite
1












I have a simple Apex Controller annotated with @RestResource. According to the documentation, this must be declared global, but the static analysis complains due to the AvoidGlobalModifier PMD rule.



Is there some other annotation I need to use to avoid the warning when my code goes through static analysis?










share|improve this question







New contributor




Jon Wolski is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

























    up vote
    5
    down vote

    favorite
    1












    I have a simple Apex Controller annotated with @RestResource. According to the documentation, this must be declared global, but the static analysis complains due to the AvoidGlobalModifier PMD rule.



    Is there some other annotation I need to use to avoid the warning when my code goes through static analysis?










    share|improve this question







    New contributor




    Jon Wolski is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.





















      up vote
      5
      down vote

      favorite
      1









      up vote
      5
      down vote

      favorite
      1






      1





      I have a simple Apex Controller annotated with @RestResource. According to the documentation, this must be declared global, but the static analysis complains due to the AvoidGlobalModifier PMD rule.



      Is there some other annotation I need to use to avoid the warning when my code goes through static analysis?










      share|improve this question







      New contributor




      Jon Wolski is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I have a simple Apex Controller annotated with @RestResource. According to the documentation, this must be declared global, but the static analysis complains due to the AvoidGlobalModifier PMD rule.



      Is there some other annotation I need to use to avoid the warning when my code goes through static analysis?







      apex restresource pmd






      share|improve this question







      New contributor




      Jon Wolski is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question







      New contributor




      Jon Wolski is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question






      New contributor




      Jon Wolski is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 42 mins ago









      Jon Wolski

      1262




      1262




      New contributor




      Jon Wolski is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Jon Wolski is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Jon Wolski is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          4
          down vote













          Your use case needs you to expose a web service. A web service should be always global. I wont worrry much about that warning, as its informative more than obstructing your work. That being said you can change that rule.



          The source code of that rule is present here:
          https://github.com/pmd/pmd/blob/master/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/bestpractices/AvoidGlobalModifierRule.java



          You can alter that rule's java file to not trigger if class contains RestResource or webservice keyword.



          Meanwhile, I have submitted it as an issue to PMD. Src: https://github.com/pmd/pmd/issues/1348






          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: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );






            Jon Wolski is a new contributor. Be nice, and check out our Code of Conduct.









             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f232446%2fsilence-the-avoidglobalmodifier-warning-in-restresource-apex-controller%23new-answer', 'question_page');

            );

            Post as a guest






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            4
            down vote













            Your use case needs you to expose a web service. A web service should be always global. I wont worrry much about that warning, as its informative more than obstructing your work. That being said you can change that rule.



            The source code of that rule is present here:
            https://github.com/pmd/pmd/blob/master/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/bestpractices/AvoidGlobalModifierRule.java



            You can alter that rule's java file to not trigger if class contains RestResource or webservice keyword.



            Meanwhile, I have submitted it as an issue to PMD. Src: https://github.com/pmd/pmd/issues/1348






            share|improve this answer
























              up vote
              4
              down vote













              Your use case needs you to expose a web service. A web service should be always global. I wont worrry much about that warning, as its informative more than obstructing your work. That being said you can change that rule.



              The source code of that rule is present here:
              https://github.com/pmd/pmd/blob/master/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/bestpractices/AvoidGlobalModifierRule.java



              You can alter that rule's java file to not trigger if class contains RestResource or webservice keyword.



              Meanwhile, I have submitted it as an issue to PMD. Src: https://github.com/pmd/pmd/issues/1348






              share|improve this answer






















                up vote
                4
                down vote










                up vote
                4
                down vote









                Your use case needs you to expose a web service. A web service should be always global. I wont worrry much about that warning, as its informative more than obstructing your work. That being said you can change that rule.



                The source code of that rule is present here:
                https://github.com/pmd/pmd/blob/master/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/bestpractices/AvoidGlobalModifierRule.java



                You can alter that rule's java file to not trigger if class contains RestResource or webservice keyword.



                Meanwhile, I have submitted it as an issue to PMD. Src: https://github.com/pmd/pmd/issues/1348






                share|improve this answer












                Your use case needs you to expose a web service. A web service should be always global. I wont worrry much about that warning, as its informative more than obstructing your work. That being said you can change that rule.



                The source code of that rule is present here:
                https://github.com/pmd/pmd/blob/master/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/bestpractices/AvoidGlobalModifierRule.java



                You can alter that rule's java file to not trigger if class contains RestResource or webservice keyword.



                Meanwhile, I have submitted it as an issue to PMD. Src: https://github.com/pmd/pmd/issues/1348







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 25 mins ago









                Pranay Jaiswal

                8,89931848




                8,89931848




















                    Jon Wolski is a new contributor. Be nice, and check out our Code of Conduct.









                     

                    draft saved


                    draft discarded


















                    Jon Wolski is a new contributor. Be nice, and check out our Code of Conduct.












                    Jon Wolski is a new contributor. Be nice, and check out our Code of Conduct.











                    Jon Wolski is a new contributor. Be nice, and check out our Code of Conduct.













                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f232446%2fsilence-the-avoidglobalmodifier-warning-in-restresource-apex-controller%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Comments

                    Popular posts from this blog

                    Long meetings (6-7 hours a day): Being “babysat” by supervisor

                    What does second last employer means? [closed]

                    One-line joke