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
Damon ShawDamon Shaw 

sforce.one.navigateToSObject(url) opens a new tab in Lightning Experience Service Console

I have an address validation visualforce page which is opened from a link on a Case, the redirect to the VF page works fine and the page does what it should outside of the Service Console.

However in the Service Console when the user clicks the save button and the page calls sforce.one.navigateToSObject('{!theCase.Id}'); it opens the case in a new tab, leaving the VF page open. The new tab opens the case it shoud but I don't want it to open in a new tab I want it to redirect the existing tab.

I've tried using sforce.one.back(); and this does the same, as does right clicking on the page and selecting back.

Is there a way to have the VF page redirect in it's current tab or a way of closing the current tab when opening a new one like we can when using in the std service console with sforce.console.closeTab(result.id);

here's a really basic view of the page
<apex:page controller="AddressVerificationController">

    <script type="text/javascript" >
        function closeTab() {
            sforce.one.navigateToSObject('{!theCase.Id}');
        }
    </script>
    
    <apex:form >
        <apex:pageBlock >
            <apex:commandLink action="{!save}" value="Save" type="button" oncomplete="closeTab()"/>
        </apex:pageBlock>
    </apex:form>
</apex:page>

and the controller
public with sharing class AddressVerificationController {

    public Case theCase { get; set; }
    
    public AddressVerificationController() {
        this.theCase = [SELECT Id, Address__c FROM Case WHERE Id = :ApexPages.currentpage().getparameters().get('id')];
    }

    public PageReference save(){

        update theCase;        
        return null;
    }
}

 
jigarshahjigarshah
As per the documentation here (https://developer.salesforce.com/docs/atlas.en-us.salesforce1.meta/salesforce1/salesforce1_dev_jsapi_sforce_one.htm), "you can use window.location to support custom Url schemes with window.location()". You could always use the window.location() to open the page in the same tab as follows.
<script type="text/javascript" >
		function navigateToCase(pCaseId) {
            window.open("/" + pCaseId,"_self");
        }
</script> 

<apex:commandLink action="{!save}" value="Save" type="button" oncomplete="navigateToCase('{!theCase.Id}')"/>

Hope this helps.

Please do not forget to mark this thread as SOLVED and answer as the BEST ANSWER if it helps address your issue.
Damon ShawDamon Shaw
Hi jigarshah,

Close but not quite, using window .open opened the Service Console, header and all inside the current tab, then once that had loaded the entire page refreshed returning me to two tabs, one with the case and one with the visualforce page, the tabs were around the other way though. It was very interesting to watch.

I reloaded the page and tried again, this time it opened a second tab and loaded the Service Console into that?!

here's a screen shot of second result for your amusement 
User-added image
jigarshahjigarshah
Can you try this?
window.open("/" + pCaseId,"_parent");

 
Damon ShawDamon Shaw
That was better than using _self but just refreshed the entire page and then showed me the Case in it's own Tab and the Visualforce page in another,

basically the same as sforce.one.navigateToSObject(); but with a page refresh thrown in
jigarshahjigarshah
You can try using this
window.location.href = "/" + pCaseId;
Damon ShawDamon Shaw
Hi jigarshah

Strangely that one didn't work at all, the browser console said it was blocked from accessing a cross-origin frame? I thought SF automatically allowed this between different SF domains? like visual.force.com and content.force.com etc

I added _parent back in and the browser console reported the same issue but did allow the page to refresh.

here's the error
User-added image
Damon ShawDamon Shaw
Hi jigarshah

just saw your window.location.href suggestion, similar issue,
User-added image
Damon ShawDamon Shaw
So at this point it doesn't look like it's possible,

I've found some documentation for Salesforce Console in Lightning Experience (https://developer.salesforce.com/docs/atlas.en-us.api_console.meta/api_console/sforce_api_console_methods_lightning.htm) but it's currently in pilot so I've logged a case to see if I can get access and asked if it's possible to access from visualforce