Loading
Salesforce now sends email only from verified domains. Read More
Set Up and Maintain Your Salesforce Organization
Table of Contents
Select Filters

          No results
          No results
          Here are some search tips

          Check the spelling of your keywords.
          Use more general search terms.
          Select fewer filters to broaden your search.

          Search all of Salesforce Help
          Replace the window.location Method

          Replace the window.location Method

          The window.location variable is a JavaScript method used to redirect the browser to a new page. JavaScript code in a Visualforce page that sets window.location directly isn't compatible with Lightning Experience. That's the bad news. The good news is that sforce.one navigation methods do the same thing, and are compatible with Lightning Experience.

          Required Editions

          Available in: Group, Professional, Enterprise, Performance, Unlimited, and Developer Editions
          User Permissions Needed
          To create, edit, or delete Visualforce pages: Customize Application

          Because window.location can be used in many ways, it’s not possible to address all of the possibilities. Let’s look at a case where window.location is used as a link to the edit page for an account. Then you can use this example, including the code samples, as a guide for addressing other occurrences of window.location in your pages. If you can determine what your window.location method is trying to do, chances are a sforce.one workaround exists.

          1. Locate window.location in the Visualforce code.
            1. From Setup, enter Visualforce in the Quick Find box, then select Visualforce Pages.
            2. Click Edit next to the Visualforce page.
            3. Search the Visualforce markup for the following: window.location.
              <apex:page standardController="Account" lightningStylesheets="true">   
                <apex:form >      
                  <apex:pageBlock >
                    <apex:pageBlockSection title="Edit">
                      <apex:commandButton value="Edit" 
                       onclick="window.location='/{!Account.Id}/e'; return false;"/>
                    </apex:pageBlockSection>
                  </apex:pageBlock>
                </apex:form> 
                <apex:detail />
              </apex:page>
          2. Determine where window.location is redirecting to. You can figure this out by testing the Visualforce page in Salesforce Classic.
          3. Find the appropriate sforce.one method to replace window.location.
          4. Replace all instances of window.location with sforce.one navigation.
            <apex:page standardController="Account" lightningStylesheets="true">   
              <apex:form >    
                <apex:pageBlock >
                  <apex:pageBlockSection title="Edit">
                    <apex:commandButton value="Edit" 
                     onclick="sforce.one.editRecord('{!Account.Id}');"/>
                  </apex:pageBlockSection>
                </apex:pageBlock>
              </apex:form>    
              <apex:detail />
            </apex:page>
          5. Save your changes.
          6. If your Visualforce page is going to be accessed in both Salesforce Classic and Lightning Experience, make both options available. Use an if statement to branch the code.
            <apex:page standardController="Account" lightningStylesheets="true">  
               <script>
                 function isLightningExperience(){
                    if (UITheme.getUITheme() === 'Theme4d' || UITheme.getUITheme() === 'Theme4u'){
                        sforce.one.editRecord('{!Account.Id}');
                    } else {
                        window.location='/{!Account.Id}/e';
                    }
                }
               </script>     
               <apex:form >    
                 <apex:pageBlock >
                   <apex:pageBlockSection title="Edit">
                     <apex:commandButton value="Edit" 
                      onclick="javascript:isLightningExperience();return false;"/>
                   </apex:pageBlockSection>
                 </apex:pageBlock>
               </apex:form>    
               <apex:detail />       
            </apex:page>
           
          Loading
          Salesforce Help | Article