5

I've always setup buttons to execute javascript on click so I can properly render the new page/tab based on where the user is at (cloud console or standard view). Today upon testing this exact bit of code, I'm hitting the notorious "sforce.console is null or not an object" when using Internet Explorer. (After some research this is affecting multiple versions of IE)

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

var url = '/apex/AccountActiveReservations?Id={!Account.Id}'; 

if (sforce.console.isInConsole()) { 
srcUp(url); 
} else { 
window.open(url,'_blank');
}

Am I doing something wrong here?

PS I've already tried doing the following: (as suggested in the ideas exchange)

{!REQUIRESCRIPT("/xdomain/xdomain.js")} 
{!REQUIRESCRIPT("/soap/ajax/26.0/connection.js")}
{!REQUIRESCRIPT("/support/console/28.0/integration.js")} 

var url = '/apex/AccountActiveReservations?Id={!Account.Id}'; 

if (sforce.console.isInConsole()) { 
srcUp(url); 
} else { 
window.open(url,'_blank');
}

Update: I have dug deeper and pulled out an existing button which works on the Campaign Member Sobject just fine. Here's the meta data

<webLinks>
    <fullName>EditOSAccount</fullName>
    <availability>online</availability>
    <displayType>button</displayType>
    <linkType>javascript</linkType>
    <masterLabel>New Edit OS Account</masterLabel>
    <openType>onClickJavaScript</openType>
    <protected>false</protected>
    <url>{!REQUIRESCRIPT(&quot;/xdomain/xdomain.js&quot;)} 
    {!REQUIRESCRIPT(&quot;/support/console/25.0/integration.js&quot;)} 

    var url = &apos;/apex/NewOwnerExperienceWizard?MemberId={!CampaignMember.Id}&apos;; 

    if (sforce.console.isInConsole()) { 
    srcUp(url); 
    } else { 
    window.location.href = url; 
    }</url>
</webLinks>

Here's the one on Account (Person Account) which is causing me issues:

<webLinks>
        <fullName>Active_Reservations</fullName>
        <availability>online</availability>
        <displayType>button</displayType>
        <linkType>javascript</linkType>
        <masterLabel>Active Reservations</masterLabel>
        <openType>onClickJavaScript</openType>
        <protected>false</protected>
        <url>{!REQUIRESCRIPT(&quot;/xdomain/xdomain.js&quot;)} 
    {!REQUIRESCRIPT(&quot;/support/console/25.0/integration.js&quot;)} 

    var url = &apos;/apex/AccountActiveReservations?Id={!Account.Id}&apos;; 

    if (sforce.console.isInConsole()) { 
    srcUp(url); 
    } else { 
    window.open(url,&apos;_blank&apos;);
    }</url>
</webLinks>

I believe this is a Salesforce bug and will be creating a ticket. If you guys or gals see something that I can try, please let me know

Update:

3/14/2014

Salesforce has finally picked up the case after a almost 2 weeks. Tier 2 support has been able to duplicate the issue within my FULL sandbox environment. He will be testing within his and let me know what results he comes up with.

3/17/2014

Looks like it's been either escalated to someone with more experience in tier 2 or it went to tier 3. Waiting back to hear from support.

3/19/2014

Salesforce Tier 3 closed the case on me stating this was development and that I need to have premium support to continue.

7/16/2014

Solution posted below.

1

1) You have missed one of the RequiredScripts :

<apex:includeScript value="/soap/ajax/26.0/connection.js"/> 

2) check this link it says how to load your JS in a specific order:

https://success.salesforce.com/issues_view?id=a1p30000000SYcEAAW

Workaround

- Load the scripts in a different order: 

<apex:includeScript value="/soap/ajax/26.0/connection.js"/>  
<apex:includeScript value="/support/console/26.0/integration.js"/>

enter image description here

  • I already saw this and tried that out too, but it did not work – Double A Feb 28 '14 at 0:13
  • what version of IE are you on ? I am on IE 9 and see no issues with the console button – Rao Feb 28 '14 at 0:31
  • Looks like IE 8. Sadly I don't have the permission to update it due to the window policies my company has in place. – Double A Feb 28 '14 at 0:34
  • I tried to test it using IE 7 , IE 8 using browserstack.com ( this is a online browser simulator, free registration required to start using the product) I found no issues with both IE8 and IE7 – Rao Feb 28 '14 at 0:42
  • 2
    I'll check out tomorrow with a coworker's computer who has a different version of IE... I'll let you know. Thanks! – Double A Feb 28 '14 at 0:49
1

This issue started to happen again... ended up just snagging some code from salesforce's javascript file to reinitialize the sforce.console logic. Its not pretty but it stopped me from getting this IE error on IE 8. This is the final code which ended up resolving the issue. Keep in mind, more things can be taken out such as unused variables, etc, but I was done at this point.

{!REQUIRESCRIPT("/xdomain/xdomain.js")}
{!REQUIRESCRIPT("/soap/ajax/26.0/connection.js")}
{!REQUIRESCRIPT("/support/console/30.0/integration.js")} 

var url = '/apex/AccountActiveReservations?Id={!Account.Id}'; 

if(sforce.console == null){
    sforce.console = (function() {
        var VERSION = '30.0'; //TODO: changed this to mark this toolkit as an internal API, also update Sfdc.xdomain.Util.usePostMessage() accordingly
        var CALLEE_NAME = 'sfdc-console';
        var txn_id = 0;
        var ON_CALL_END = 'onCallEnd';
        var ADD_EVENT_LISTENER = 'addEventListener';
        var ADD_PUSH_NOTIFICATION_LISTENER = 'addPushNotificationListener';
        var caller;
        var registry;

        /**
         * A class representing a generic registry for storing event and regular function callbacks
         */
        var Registry = function() {
            this.registry = {};
        };

        Registry.prototype.registerFunction = function(funcName, func, scope) {
            this.registry[funcName] = {func : func, scope : scope};
        };

        Registry.prototype.getFunction = function(funcName) {
            return this.registry[funcName];
        };

        Registry.prototype.removeFunction = function(funcName) {
            delete this.registry[funcName];
        };

        var canvasClient = (function() {
            var parsedRequest = null;

            return {
                isCanvasContext : function() {
                    return !!(typeof Sfdc !== 'undefined' && Sfdc.canvas && Sfdc.canvas.client);
                },

                // this is called from isInConsole API
                // need to make sure canvas is enabled and JSON is available because isInConsole 
                // can be called from standard app with older browsers (IE7)
                isInConsole : function () {
                    if (this.isCanvasContext()) {
                        parsedRequest = this.getParsedRequest();

                        if (parsedRequest) {
                            var environment = parsedRequest.context.environment;
                            if (environment && environment.parameters.isInConsole) {
                                return true;
                            }
                        }
                    }
                    return false;
                }
            };
        })();

        return {
            /**
             * Return true if this page is a console page
             */
            isInConsole: function() {
                var qs = location.search;

                return (qs.length !== 0 && ((qs.indexOf("?isdtp=") > -1) 
                    || (qs.indexOf("&isdtp=") > -1)))
                    || canvasClient.isInConsole();
            }
        };
    })();
}

if (sforce.console.isInConsole()) { 
srcUp(url); 
} else { 
window.open(url,'_blank');
}

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.