function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
David Herrero 5David Herrero 5 

sforce.one.navigateToURL not working in Visualforce page

Hi,
I am totally new with lightning and I am trying to switch some objtects from classic to lightning.
I have one visualforce page that checks one variable, and if it is true it redirects to another direction.
In classic it uses the "window.location.href", but it won't work with lightning, so I have added the following code:
 
<apex:form id="form">
        
        <apex:outputPanel rendered="{!$User.UIThemeDisplayed == 'Theme4d'}">
            
            <script type="text/javascript">
            
            var precondition = {!Lead.Conversion_Precondition__c} || {!ISBLANK(Lead.RecordTypeId)};  
            
            if(precondition){
                String url="{!URLFOR($Action.Lead.Convert, Lead.Id, [retURL='/' + Lead.Id, nooppti=1, IsReminderSet_fu=0], true)}";
                sforce.one.navigateToSObject(url);
            }
            </script>        
        </apex:outputPanel>
        <apex:outputPanel rendered="{!$User.UIThemeDisplayed == 'Theme3'}">
            <script type="text/javascript">
            var precondition = {!Lead.Conversion_Precondition__c} || {!ISBLANK(Lead.RecordTypeId)};  
            if(precondition){
                
                window.location.href = "{!URLFOR($Action.Lead.Convert, Lead.Id, [retURL='/' + Lead.Id, nooppti=1, IsReminderSet_fu=0], true)}";
            }
            </script>
        </apex:outputPanel>

even if I put the sforce.one.navigateto alone it does not work.
any suggestion?

Thanks
Laxman Vattam 26Laxman Vattam 26
Try this. This should work. Window.location doesnt work in lightning mode.
sforce.one.navigateToURL('/apex/VFPageName?RecordType=recordtypeid');
Laxman Vattam 26Laxman Vattam 26
If you need to launch standard page for create records instead of VF page, use as below:
sforce.one.createRecord('Account', '{!AccountRecordTypeId}');
David Herrero 5David Herrero 5
I opened a case to SAlesforce, and after one week we concluded that the problem was trying to open the lead convertion page in Lightning. 
The problem was not with the function (sforce.one.navigateToURL) but with the url I tried to open.

Thanks for your help Laxman
Bert Van HoveBert Van Hove
@David How did u manage this? I'm running into the same issue. I don't have an idea how to access the convert page in lightning from a VFP