I have a button in a custom sidebar object that creates a task when clicked. If an object is being viewed the task should be related to that object. If an object is not being viewed (your are on a list view etc) it should create a task not related to anything.

I use javascript to examine the URL to determine if the page is an object or not.

createTask  = function() {
        var id = window.location.pathname.split('/')[1];
        if(typeof(id.length) != 'undefined' && id.length > 3){
            //Do work creating task related to id
        } else {
            //Do work creating task, no relation

While this is working, it is not the best way. For example, when you are on the Home tab the id split out of the url comes in as 'home'. (From the URL na15.salesforce.com/home/home.jsp) This is more than 3 characters and the task creation fails.

Is there a better way to determine if the user is viewing an object?

I found the property window.sfdcPage.entityId which in my tests resolves to an id (example 003i000000YQmrB) when viewing an object but is 'undefined' when on a list view or other page.

This post on developer.salesforce.com suggests that it will work great.

Would this be a more reliable method to use?


You must log in to answer this question.

Browse other questions tagged .