0

How can I get the ID of the record regardless of the type of tab that is displaying a custom button. For example at the minute I have a button on an Order object that gets the ID like so:

{!REQUIRESCRIPT("/support/console/39.0/integration.js")}

var sfdcUrlName = window.location.protocol + '//' + window.location.host;

var myParentTabId = '';

// Here evaluating a parent tab ID
var readParentId = function(result){
myParentTabId = result.id;
};

sforce.console.getEnclosingPrimaryTabId(readParentId);

var objID = '';
var showObjectId = function(result) {
objID = result.id;
};
sforce.console.getFocusedPrimaryTabObjectId(showObjectId);

var openSubtab = function(result){
sforce.console.openSubtab(myParentTabId, sfdcUrlName + '/apex/VFPAGE?id=' + objID , true, 'VFPAGE',null);
};
sforce.console.getEnclosingTabId(openSubtab);

As my visualforce page uses the Order Standard Controller (and I'd rather not change this) you may realise that if the primary Tab is not showing an Order detail ID then a visualforce error is displayed

Id XXXXXXXXXX is not valid for the Order standard controller

I know there are methods like getEnclosingTabID, getfocusedSubTab and getFocusedPrimaryTabObjectID as above and presumably I need to use a few in conjunction but whilst getEnclosingTabID gives me the focused tab id I don't know how to use this to get the record id.

I hope that makes sense.

What I am wondering is what do I use to get the ID of the record from the focused tab regardless of whether it is a primary or sub-tab?

0

If I understand your question correctly, you want to get the record ID out of a tab via a button. But you don't necessarily know if the button will be in a primary tab or sub tab at the time it's clicked.

I would suggest a combination of getEnclosingTabID and getPageInfo methods. You feed the enclosing tab ID into the getPageInfo method which in turn gives you the info about that tab in a JSON format.

sforce.console.getEnclosingTabId(getRecordId);

var getRecordId = function getRecordId(result) { 
    var tabId = result.id;
    sforce.console.getPageInfo(tabId, doSomething);   
} 

var doSomething = function doSomething(result) {    
    var parsedInfo = JSON.parse(result.pageInfo);
    var myObjectId = parsedInfo.objectId; 
} 

https://developer.salesforce.com/docs/atlas.en-us.api_console.meta/api_console/sforce_api_console_getenclosingtabid.htm

https://developer.salesforce.com/docs/atlas.en-us.api_console.meta/api_console/sforce_api_console_getpageinfo.htm

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.