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
Mr. AdminMr. Admin 

How to make the Cancel button close the Case Edit page within the Salesforce Console?

Hello,

We have a Visualforce redirect in place on the Case Record Type page, so when a user selects one of the (6) record types, they are taken to a visualforce edit page that is unique to that individual record type.

At the top of each page is a 'Save' and 'Cancel' button that uses this code:
<apex:pageblockbuttons >
                <apex:commandbutton action="{!save}" value="Save"></apex:commandbutton>
                <apex:commandbutton action="{!cancel}" value="Cancel"></apex:commandbutton>
 </apex:pageblockbuttons>
When a user is within the Salesforce Console and they create a brand new case, the screen splits and a new tab is opened (see screenshot below). 

User-added image

The problem occurs when the user clicks the 'Cancel' button. The page simply refreshes and loads the Salesforce Console 'Home tab'.

User-added image

1) How do you program the button so it simply closes the tabbed section?
2) How do you relabel the tab so it says something other than 'External Page'?


Thank you for your help.


Thank
Best Answer chosen by Mr. Admin
logontokartiklogontokartik
Since you are working in the Console, you need to use special Javascript methods to do the functions you are requesting. 

Please refer to http://www.salesforce.com/us/developer/docs/api_console/api_console.pdf

the specific method to close the tab is closeTab(), but before that you need to get the Tab Id which you can get by using method getFocusedPrimaryTabId()

You can also relabel the tab by using method setTabTitle()

Hope this helps

All Answers

logontokartiklogontokartik
Since you are working in the Console, you need to use special Javascript methods to do the functions you are requesting. 

Please refer to http://www.salesforce.com/us/developer/docs/api_console/api_console.pdf

the specific method to close the tab is closeTab(), but before that you need to get the Tab Id which you can get by using method getFocusedPrimaryTabId()

You can also relabel the tab by using method setTabTitle()

Hope this helps
This was selected as the best answer
Mr. AdminMr. Admin
Thank you for the rapid response, this definitely helps! Looking at the sample code within the API guide, they create a hyperlink that closes the tab. How do I associate the action with the 'Cancel' button instead of having the user click on a hyperlink? Is there a way to call the testCloseTab function "onclick" of the Cancel button?

Here is the code I currently have:

<A HREF="#" onClick="testSetTabTitle();return false">
</A>

<A HREF="#" onClick="testCloseTab();return false">
Click here to close this tab</A>

<apex:includeScript value="/support/console/25.0/integration.js"/>

<script type="text/javascript">
sforce.console.getFocusedPrimaryTabId(function(result){
sforce.console.setTabTitle('* New Case', result.id);
});

function testCloseTab() {
//First find the ID of the current tab to close it
sforce.console.getEnclosingTabId(closeSubtab);
}
var closeSubtab = function closeSubtab(result) {
//Now that we have the tab ID, we can close it
var tabId = result.id;
sforce.console.closeTab(tabId);
};
</script>


logontokartiklogontokartik
You can use something like below, onclick event will basically call the Javascript function.

<apex:commandbutton onclick="testCloseTab();" value="Cancel" ></apex:commandbutton>



Mr. AdminMr. Admin
Thank you very much, that did it! I had to update the <apex:includeScript value="/support/console/25.0/integration.js"/> to use version 30.0 as well.