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
rohitrrohitr 

Pass Console Id (Primary Object Id) to controller.

How to pass id using the console functon "sforce.console.getFocusedPrimaryTabObjectId()" to a controller.
I'm getting the same on the javascript. But cannot pass. Tried using hiddenfield and actionfunction.
javascript:
function testGetFocusedPrimaryTabObjectId() {
            sforce.console.getFocusedPrimaryTabObjectId(showObjectId);
        }
        var showObjectId = function showObjectId(result) {
            //Display the object ID
            invokeController(result.id);
            alert('Object ID: ' + result.id);
        };

page:
<apex:actionFunction name="invokeController" action="{!save}" reRender="outtext">
            <apex:param value="{!primeTabValue}"/>
        </apex:actionFunction>
this is my code and in controller am using get; set; for the primeTabValue variable.

Am able to get the id on alert box. but not on the variable.

Any help would be much appreciated.


Ashish_SFDCAshish_SFDC
Hi Rohit, 


Try if this helps, 

//First find the ID of the primary tab to put the new subtab in
            sforce.console.getEnclosingPrimaryTabId(openSubtab);


//First find the ID of the current primary tab
      sforce.console.getFocusedPrimaryTabId(getCaseId);

https://developer.salesforce.com/forums/ForumsMain?id=906F000000096sGIAQ


Also Vote for this Idea, 

https://success.salesforce.com/ideaView?id=08730000000XhSBAA0


Regards,
Ashish

Andreas MeyerAndreas Meyer
Hi Rohit,

in fact your class member variable "primeTabValue" isn't assigned at all, if you do it like that. In your method "InvokeController" do this:

String message = Apexpages.currentPage().getParameters().get('primeTabValue'); 

and you will get the value. You don't need the class member variable at that point.

Best,
Andreas
msantanamsantana
I had the same problem and it took me awhile to figure out. There are not example of Custom console components.

Visualforce page: 
In this example you have two ways of passing the ID to the controller to then build your code since the normal way to get the parameters does not work (ApexPages.currentPage().getParameters().get('id');) This is due to the fact that tab are encapsulated like in a iframe.
Also keep in mind that since the console does not behave the same as a regular Visualforce page and the extension controller is not getting information from your current object you can't populate the data.  For that reason, you would need to build the controller.
VF page:
<apex:page standardController="Case" extensions="CaseConsoleControllerExt"> 
    <apex:includeScript value="/support/console/42.0/integration.js"/>
    <script type="text/javascript">
        if(sforce.console){
            function GetPrimaryTabObjectId() {
                sforce.console.getFocusedPrimaryTabObjectId(showObjectId);
                }
            var showObjectId = function showObjectId(result) {
                //Display the object ID
                assignVar(result.id);
                alert('Object ID: '+result.id);
            }
           sforce.console.onCustomConsoleComponentButtonClicked(GetPrimaryTabObjectId);
        }
    </script>
    <!-- BOF Error section -->
    <apex:pageMessages />

    <!-- EOF Error section -->
   <apex:form >
       <apex:pageBlock title="To Update SoldTo in Case inorder to get DIG" >
            <apex:pageBlockSection columns="1">
                <apex:inputField value="{!case.status}" /> //No populating current case value. To be resolved
            </apex:pageBlockSection>
            <apex:pageBlockButtons >
               <apex:commandButton action="{!save}" value="Update"/>
            </apex:pageBlockButtons>
        <apex:actionFunction name="assignVar" onComplete="alert('Action Completed')" action="{!returnVar}">
            <apex:param name="cid" value="" assignTo="{!consoleId}"/>
        </apex:actionFunction>
        </apex:pageBlock>
    </apex:form>
    <a href="#" onClick="GetPrimaryTabObjectId();return false">Click here to get the object ID of the focused subtab</a>
</apex:page>

Controller:
public with sharing class CaseConsoleControllerExt {
   public Id consoleId { get; set;}
   public void returnVar() {// This is where you get the param sent from the VF page
        System.debug('consoleId ' + consoleId);
   }
  public CaseConsoleControllerExt(ApexPages.StandardController controller) {
        // Do thonthing here
  }
}