Different values from URL.getSalesforceBaseUrl().toExternalForm()

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

favorite












I have a managed app that uses URL.getSalesforceBaseUrl().toExternalForm() to create a Remote site for ToolingApi. This works great in all environments (Production, Dev/scratch org), however, it's pretty unreliable in Sandboxes. Sometimes it returns the proper URL sometimes it doesn't.



For example: While running the app in a sandbox, this line of code



URL.getSalesforceBaseUrl().toExternalForm()
returns https://examplesite--testing.my.salesforce.com



However, using that same method inside Execute anonymous returns
https://exmplesite--testing.cs61.my.salesforce.com which is the correct url needed for the toolingApi.



Anyone have any insight on what could be happening?










share|improve this question







New contributor




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

























    up vote
    4
    down vote

    favorite












    I have a managed app that uses URL.getSalesforceBaseUrl().toExternalForm() to create a Remote site for ToolingApi. This works great in all environments (Production, Dev/scratch org), however, it's pretty unreliable in Sandboxes. Sometimes it returns the proper URL sometimes it doesn't.



    For example: While running the app in a sandbox, this line of code



    URL.getSalesforceBaseUrl().toExternalForm()
    returns https://examplesite--testing.my.salesforce.com



    However, using that same method inside Execute anonymous returns
    https://exmplesite--testing.cs61.my.salesforce.com which is the correct url needed for the toolingApi.



    Anyone have any insight on what could be happening?










    share|improve this question







    New contributor




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





















      up vote
      4
      down vote

      favorite









      up vote
      4
      down vote

      favorite











      I have a managed app that uses URL.getSalesforceBaseUrl().toExternalForm() to create a Remote site for ToolingApi. This works great in all environments (Production, Dev/scratch org), however, it's pretty unreliable in Sandboxes. Sometimes it returns the proper URL sometimes it doesn't.



      For example: While running the app in a sandbox, this line of code



      URL.getSalesforceBaseUrl().toExternalForm()
      returns https://examplesite--testing.my.salesforce.com



      However, using that same method inside Execute anonymous returns
      https://exmplesite--testing.cs61.my.salesforce.com which is the correct url needed for the toolingApi.



      Anyone have any insight on what could be happening?










      share|improve this question







      New contributor




      user60315 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 managed app that uses URL.getSalesforceBaseUrl().toExternalForm() to create a Remote site for ToolingApi. This works great in all environments (Production, Dev/scratch org), however, it's pretty unreliable in Sandboxes. Sometimes it returns the proper URL sometimes it doesn't.



      For example: While running the app in a sandbox, this line of code



      URL.getSalesforceBaseUrl().toExternalForm()
      returns https://examplesite--testing.my.salesforce.com



      However, using that same method inside Execute anonymous returns
      https://exmplesite--testing.cs61.my.salesforce.com which is the correct url needed for the toolingApi.



      Anyone have any insight on what could be happening?







      apex lightning sandbox debugging






      share|improve this question







      New contributor




      user60315 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




      user60315 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




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









      asked 4 hours ago









      user60315

      211




      211




      New contributor




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





      New contributor





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






      user60315 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
          2
          down vote













          In Winter 19, we will have a new method, System.Url.getOrgDomainUrl(), which will always return the correct URL.




          Use the new System.Url.getOrgDomainUrl() method to interact with Salesforce REST and SOAP APIs in Apex code. Get
          endpoints for User Interface API calls, for creating and customizing picklist value sets and custom fields, and more. Use the updated
          System.UserInfo.getSessionId() method to retrieve session IDs, even when your code runs asynchronously.




          The System.URL.getSalesforceBaseUrl() method is intended to return the host for the current context (e.g. Lightning, Visualforce, Classic UI, Communities). This new method will always return the correct My Domain URL that should be used, and should work correctly with all Sandboxes.






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



            );






            user60315 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%2f232847%2fdifferent-values-from-url-getsalesforcebaseurl-toexternalform%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
            2
            down vote













            In Winter 19, we will have a new method, System.Url.getOrgDomainUrl(), which will always return the correct URL.




            Use the new System.Url.getOrgDomainUrl() method to interact with Salesforce REST and SOAP APIs in Apex code. Get
            endpoints for User Interface API calls, for creating and customizing picklist value sets and custom fields, and more. Use the updated
            System.UserInfo.getSessionId() method to retrieve session IDs, even when your code runs asynchronously.




            The System.URL.getSalesforceBaseUrl() method is intended to return the host for the current context (e.g. Lightning, Visualforce, Classic UI, Communities). This new method will always return the correct My Domain URL that should be used, and should work correctly with all Sandboxes.






            share|improve this answer
























              up vote
              2
              down vote













              In Winter 19, we will have a new method, System.Url.getOrgDomainUrl(), which will always return the correct URL.




              Use the new System.Url.getOrgDomainUrl() method to interact with Salesforce REST and SOAP APIs in Apex code. Get
              endpoints for User Interface API calls, for creating and customizing picklist value sets and custom fields, and more. Use the updated
              System.UserInfo.getSessionId() method to retrieve session IDs, even when your code runs asynchronously.




              The System.URL.getSalesforceBaseUrl() method is intended to return the host for the current context (e.g. Lightning, Visualforce, Classic UI, Communities). This new method will always return the correct My Domain URL that should be used, and should work correctly with all Sandboxes.






              share|improve this answer






















                up vote
                2
                down vote










                up vote
                2
                down vote









                In Winter 19, we will have a new method, System.Url.getOrgDomainUrl(), which will always return the correct URL.




                Use the new System.Url.getOrgDomainUrl() method to interact with Salesforce REST and SOAP APIs in Apex code. Get
                endpoints for User Interface API calls, for creating and customizing picklist value sets and custom fields, and more. Use the updated
                System.UserInfo.getSessionId() method to retrieve session IDs, even when your code runs asynchronously.




                The System.URL.getSalesforceBaseUrl() method is intended to return the host for the current context (e.g. Lightning, Visualforce, Classic UI, Communities). This new method will always return the correct My Domain URL that should be used, and should work correctly with all Sandboxes.






                share|improve this answer












                In Winter 19, we will have a new method, System.Url.getOrgDomainUrl(), which will always return the correct URL.




                Use the new System.Url.getOrgDomainUrl() method to interact with Salesforce REST and SOAP APIs in Apex code. Get
                endpoints for User Interface API calls, for creating and customizing picklist value sets and custom fields, and more. Use the updated
                System.UserInfo.getSessionId() method to retrieve session IDs, even when your code runs asynchronously.




                The System.URL.getSalesforceBaseUrl() method is intended to return the host for the current context (e.g. Lightning, Visualforce, Classic UI, Communities). This new method will always return the correct My Domain URL that should be used, and should work correctly with all Sandboxes.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 2 hours ago









                sfdcfox

                227k10175389




                227k10175389




















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









                     

                    draft saved


                    draft discarded


















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












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











                    user60315 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%2f232847%2fdifferent-values-from-url-getsalesforcebaseurl-toexternalform%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Comments

                    Popular posts from this blog

                    What does second last employer means? [closed]

                    Installing NextGIS Connect into QGIS 3?

                    One-line joke