I have a custom console component on which I want to display the details of the active primary tab (e.g. Id, Name, Email, CaseNumber etc), which can be a case details or contact details depending on the tab that is open at that time. What is the best way to achieve this? Any help is appreciated.
2 Answers
It sounds like what you're getting is the ID of the tab when what you really want is the ID of the object.
For this you can use sforce.console.getFocusedPrimaryTabObjectId instead of sforce.console.getFocusedPrimaryTabId.
Note that you'll probably want to also setup a listener on one or both of sforce.console.onFocusedPrimaryTab and sforce.console.onFocusedSubtab.
Lastly, if you want to hide your custom console component when the user has closed all the primary tabs you'll probably also need to setup a listener for close tab events so that when the current tab is closed, you can do a hide (until a new one is opened and then show):
sforce.console.addEventListener(sforce.console.ConsoleEvent.CLOSE_TAB,
onEnclosingPrimaryTabClose,
{ tabId : result.id }
);
Hope this helps!
You can use "getFocusedPrimaryTabId" method to get record id of currently focused primary tab. for e.g.:-
<apex:page>
<A HREF="#" onClick="testGetFocusedPrimaryTabId();return false">
Click here to get the focused primary tab ID</A>
<apex:includeScript value="/support/console/25.0/integration.js"/>
<script type="text/javascript">
function testGetFocusedPrimaryTabId() {
sforce.console.getFocusedPrimaryTabId(showTabId);
}
var showTabId = function showTabId(result) {
//Display the tab ID
alert('Tab ID: ' + result.id);
};
</script>
</apex:page>
Find details at https://developer.salesforce.com/docs/atlas.en-us.api_console.meta/api_console/sforce_api_console_getfocusedprimarytabid.htm
You can use "getPrimaryTabIds" method to get ids of all open primary tabs,
<script type="text/javascript">
function testGetPrimaryTabIds() {
sforce.console.getPrimaryTabIds(showTabId);
}
//declare callback method to receive response from Salesforce console
var showTabId = function showTabId(result) {
//Display the primary tab IDs
alert('Primary Tab IDs: ' + result.ids);
};
</script>
for more details refer https://developer.salesforce.com/docs/atlas.en-us.api_console.meta/api_console/sforce_api_console_getprimarytabids.htm?search_text=primary%20tab
-
Thanks Anshul. I should have mentioned that I have already tried this but I was getting scc-pt-0 in the result. I don't know what this is and what I need is the 15 digit id. Also, can I get this id from the controller directly? Commented Jun 8, 2015 at 1:39
-
are you using a custom visualforce page with custom/ extension controller?– AnshulCommented Jun 8, 2015 at 5:21
-
Yes I am using a custom vf page with a custom controller Commented Jun 8, 2015 at 10:48
-
In case of a custom controller you can simply get the id in apex itself. You can use currentpagereference to get the querystring parameters. For e.g. if the querystring parameter being used for id is "id" then you can use String tabRecordId = System.currentPageReference().getParameters().get('id');– AnshulCommented Jun 8, 2015 at 15:34