+ Start a Discussion

Commandbutton Behavior in Primary Tab and Subtab in Service Console

I have a commandbutton within a VF page that invokes a controller method.  When I load the VF page in a subtab, the method gets called.  But when I load the VF page in a primary tab, the method is not getting called. 

Here is the code snippet in my Launcher VF Page that decides whether to open a Primary Tab or a Subtab in the Service Console:

        var tabId;
        var resultId;
        //Callback function of getFocusedPrimaryTabId
        var showTabId = function showTabId(result) {
            tabId = result.id;
            //Open Search page as SUBTAB
            sforce.console.openSubtab(tabId, '/apex/ServiceRequestSearch?id=' + resultId, true, 'Service Request Search', null);
        //Callback function of getFocusedPrimaryTabObjectId
        var getObjId = function getObjId(result) {
if(result.id != 'null'){
      resultId = result.id;
                    //Open Search page as PRIMARY TAB
                    sforce.console.openPrimaryTab(null, '/apex/ServiceRequestSearch?id=', true, 'Service Request Search')

Here is the command button that I have in the Search VF Page:

<apex:commandButton value="Search" action="{!doSearch}" rerender="resultBlock" status="searchStatus"/> 

And here's the doSearch method in the controller:

    public PageReference doSearch() {

     System.debug('METHOD START:  doSearch');
     List<String> caseIDList = new List<String>();
     //Compose dynamic SOSL query
     FindQuery =  'FIND\'' + SearchText + '\'IN ALL FIELDS RETURNING Case(Id, CaseNumber, ' +
         'Origin, Status, Priority, Subject, CreatedDate, Owner.Name, Division__c, Account.Name WHERE ';
        //Add Case Status in filter if a Status has been selected
        if (selectedStatus <> '--All--') {          
         FindQuery = FindQuery + ' and Status = \'' + selectedStatus + '\'';       
        //Add Case Priority in filter if a Priority has been selected
        if (selectedPriority <> '--All--'){          
         FindQuery = FindQuery + ' and Priority = \'' + selectedPriority + '\'';       
        //Add Case Origin in filter if an Origin has been selected
        if (selectedOrigin <> '--All--'){          
         FindQuery = FindQuery + ' and Origin = \'' + selectedOrigin + '\'';       
        //Search Results sorting logic
        //Sort by Created Date Descending
        if(selectedSorting == 'createDesc'){
         FindQuery = FindQuery + ' ORDER BY CreatedDate DESC)';
        //Sort by Created Date Ascending
        else if(selectedSorting == 'createAsc'){
         FindQuery = FindQuery + ' ORDER BY CreatedDate ASC)';
        try { 
            //Run SOSL Query
         List<List<SObject>> searchResultList = Search.query(FindQuery);
         caseList = ((List<Case>)searchResultList[0]);
        catch(Exception ex) {
         System.debug('ERROR:' + ex);
        return null;
Kindly clarify few points  -: 

- Have you used alerts to know how much code part is working ? 

- Could you kindly confirm that are you able to open the sub tab ?
 - In the comment you have mentioned that you need the Object ID of the focused primary tab but in the actual
  code you are getting the PrimaryTabID
  - How are you loading the script on Page - : Onload or any action.

Let me know if you have any query