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
Rajesh Reddy 29Rajesh Reddy 29 

Close primary tab in console while clicking custom Visualforce Edit Button

Hi Team,
 
I have custom VF Button for object detail page when I will click it is opening new edit page in console I need to close primary tab .
Can anyone help me on this as urgent. thanks  in Advance.
 
Regards,
Rajesh
 
NagendraNagendra (Salesforce Developers) 
Hi Rajesh,

Please find the sample code below and tweak it as per your requirement which should suffice.
sforce.console.openPrimaryTab(null, '/apex/LMT_LeadDeduplication?scontrolCaching=1&id={!Lead.Id}', true);   

var closeSubtab = function closeSubtab(result) {
     var tabId = result.id;
     sforce.console.closeTab(tabId);
   };
sforce.console.getEnclosingPrimaryTabId(closeSubtab);
If you wanted to keep the same primary tab for some reason, you can use openPrimaryTab to override the tab itself by providing the ID. Then your button would just look like this
{!REQUIRESCRIPT("/support/console/36.0/integration.js")}
{!REQUIRESCRIPT("/soap/ajax/36.0/connection.js")} 
try { 
   sforce.console.getEnclosingPrimaryTabId(function (result)
   {
     sforce.console.openPrimaryTab(result.id, '/apex/LMT_LeadDeduplication?scontrolCaching=1&id={!Lead.Id}', true);
   });  
}
catch(e){ 
   alert('An Error has Occured. Error:' +e); 
}
Hope this should help you resolved the issue.

Kindly mark this as solved if my reply was helpful so that it gets removed from the unanswered queue which results in helping others who are encountering a similar issue.

Thanks,
Nagendra