Switch: Enum value used in 'when expression' should be unqualified

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
1
down vote

favorite












Background



I am getting this error message three times:




Enum value used in 'when expression' should be unqualified




In relation to this code:



Schema.DisplayType fieldType = getType(fieldName);

switch on fieldType
when Schema.DisplayType.STRING // this line errors
// do stuff

when Schema.DisplayType.CURRENCY // this line errors
// do stuff

when Schema.DisplayType.DOUBLE // this line errors
// do stuff

when else
throw new CustomException('Unknown field type: ' + fieldType);




Questions



  1. Why am I getting the error?

  2. How do I fix it?









share|improve this question



























    up vote
    1
    down vote

    favorite












    Background



    I am getting this error message three times:




    Enum value used in 'when expression' should be unqualified




    In relation to this code:



    Schema.DisplayType fieldType = getType(fieldName);

    switch on fieldType
    when Schema.DisplayType.STRING // this line errors
    // do stuff

    when Schema.DisplayType.CURRENCY // this line errors
    // do stuff

    when Schema.DisplayType.DOUBLE // this line errors
    // do stuff

    when else
    throw new CustomException('Unknown field type: ' + fieldType);




    Questions



    1. Why am I getting the error?

    2. How do I fix it?









    share|improve this question























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      Background



      I am getting this error message three times:




      Enum value used in 'when expression' should be unqualified




      In relation to this code:



      Schema.DisplayType fieldType = getType(fieldName);

      switch on fieldType
      when Schema.DisplayType.STRING // this line errors
      // do stuff

      when Schema.DisplayType.CURRENCY // this line errors
      // do stuff

      when Schema.DisplayType.DOUBLE // this line errors
      // do stuff

      when else
      throw new CustomException('Unknown field type: ' + fieldType);




      Questions



      1. Why am I getting the error?

      2. How do I fix it?









      share|improve this question













      Background



      I am getting this error message three times:




      Enum value used in 'when expression' should be unqualified




      In relation to this code:



      Schema.DisplayType fieldType = getType(fieldName);

      switch on fieldType
      when Schema.DisplayType.STRING // this line errors
      // do stuff

      when Schema.DisplayType.CURRENCY // this line errors
      // do stuff

      when Schema.DisplayType.DOUBLE // this line errors
      // do stuff

      when else
      throw new CustomException('Unknown field type: ' + fieldType);




      Questions



      1. Why am I getting the error?

      2. How do I fix it?






      apex enum switch-case






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 1 hour ago









      Robs

      1,141423




      1,141423




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          3
          down vote



          accepted










          You need to take the namespace and enclosing class qualifiers off of the enum values. It knows what you mean because it know the type of the value you are switching on. So, you need to write it like this:



          Schema.DisplayType fieldType = getType(fieldName);

          switch on fieldType
          when STRING
          // do stuff

          when CURRENCY
          // do stuff

          when DOUBLE
          // do stuff

          when else
          throw new CustomException('Unknown field type: ' + fieldType);







          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
            );



            );













             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f234174%2fswitch-enum-value-used-in-when-expression-should-be-unqualified%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
            3
            down vote



            accepted










            You need to take the namespace and enclosing class qualifiers off of the enum values. It knows what you mean because it know the type of the value you are switching on. So, you need to write it like this:



            Schema.DisplayType fieldType = getType(fieldName);

            switch on fieldType
            when STRING
            // do stuff

            when CURRENCY
            // do stuff

            when DOUBLE
            // do stuff

            when else
            throw new CustomException('Unknown field type: ' + fieldType);







            share|improve this answer
























              up vote
              3
              down vote



              accepted










              You need to take the namespace and enclosing class qualifiers off of the enum values. It knows what you mean because it know the type of the value you are switching on. So, you need to write it like this:



              Schema.DisplayType fieldType = getType(fieldName);

              switch on fieldType
              when STRING
              // do stuff

              when CURRENCY
              // do stuff

              when DOUBLE
              // do stuff

              when else
              throw new CustomException('Unknown field type: ' + fieldType);







              share|improve this answer






















                up vote
                3
                down vote



                accepted







                up vote
                3
                down vote



                accepted






                You need to take the namespace and enclosing class qualifiers off of the enum values. It knows what you mean because it know the type of the value you are switching on. So, you need to write it like this:



                Schema.DisplayType fieldType = getType(fieldName);

                switch on fieldType
                when STRING
                // do stuff

                when CURRENCY
                // do stuff

                when DOUBLE
                // do stuff

                when else
                throw new CustomException('Unknown field type: ' + fieldType);







                share|improve this answer












                You need to take the namespace and enclosing class qualifiers off of the enum values. It knows what you mean because it know the type of the value you are switching on. So, you need to write it like this:



                Schema.DisplayType fieldType = getType(fieldName);

                switch on fieldType
                when STRING
                // do stuff

                when CURRENCY
                // do stuff

                when DOUBLE
                // do stuff

                when else
                throw new CustomException('Unknown field type: ' + fieldType);








                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 43 mins ago









                Aidan

                5,903937




                5,903937



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f234174%2fswitch-enum-value-used-in-when-expression-should-be-unqualified%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Comments

                    Popular posts from this blog

                    What does second last employer means? [closed]

                    List of Gilmore Girls characters

                    Confectionery