1

I have a custom button on custom object detail page and onclick of that button in console it opens a subtab and the vf page opens there. I want that onclick of button on detail page, the vfpage should be loaded in the same page. Adding my current code here which works fine in classic but not in console.

{!REQUIRESCRIPT('/soap/ajax/27.0/connection.js')} 
{!REQUIRESCRIPT("/support/console/30.0/integration.js")} 
var pStatus = '{!custObj__c.Status__c}'; 
var redirect = '/apex/vfPage?Id={!custObj__c.Id}' 
if(pStatus != 'abc' || {!custObj__c.xyz__c}>0) 
{ 
alert('No .....'); 
} 
else if (sforce.console.isInConsole()) 
{ 
srcUp(redirect); 
} 
else{ 
window.location.href= redirect; 
}

Script for button :

 function redirectToObjForConsole(urlRedi){  
      closeTab();
      sforce.console.openPrimaryTab(undefined,urlRedi, true, 'abc');   
    }

    //The callback function that closeTab will call once it has the ID for its tab
    var callCloseTab= function callCloseTab(result) {
       sforce.console.closeTab(result.id);
    }

    function closeTab(){
       sforce.console.getEnclosingTabId(callCloseTab);
    }


    //call functionn
    redirectToObjForConsole('')

Save functionality code :

 public PageReference save(){
        Savepoint sp = Database.setSavepoint();

        List<custObj__c> posaList = new List<custObj__c>();
        try{
            List<Fin__c> selectedFAs = new List<Fin__c>();
            for(FinAllocWrapper faWrap: faList) {
                if(faWrap.selected == true) {
                    selectedFAs.add(faWrap.fa);
                    //selectedContacts.add(faWrap.con);
                }
            }

            if(selectedFAs.isEmpty()){
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'abc.'));
                return null;
            }

            //for(Contact con: selectedContacts) {
            for (Fin__c fa : selectedFAs) {
                custObj__c pos = new custObj__c();
                posaList.add(pos);
            }
            if (!posaList.isEmpty()) {
                upsert posaList;
            }
            return new PageReference('/' + p.Id);
        }     
        catch(Exception ex){
            Database.rollback(sp);
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'An Error Occured please contact your Administrator.'));
            system.debug('----'+ ex.getmessage() +  ' ' + ex.getLineNumber() );
            return null;
        }
    } 
2

To open the visualforce page in the same tab in Console use, srcSelf()

if (sforce.console.isInConsole()) 
{ 
  srcSelf(redirect); 
}

For more information, about navigation, refer my blog, Different ways of navigation

  • Hi Santanu, it works fine, but the only problem is once I do the functionality on page and click save button it shows the classic view and then goes back to console detailed page. I don't want the classic view to be shown. I am adding a script in my question. Can you please check that – wizard Apr 25 '17 at 5:21
  • updated the ques. And added the save code – wizard Apr 25 '17 at 5:41
  • refer this link for returning to console. salesforce.stackexchange.com/questions/101730/… – Santanu Boral Apr 25 '17 at 5:45
  • it should be specific to both classic and console so I cnt give the console url – wizard Apr 25 '17 at 6:05
  • you can pass parameter from the url either classic or console indicator and parse the parameter in controller and finally return the page accordingly – Santanu Boral Apr 25 '17 at 6:07

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.