Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I'm using a Homepage Component to make an AJAX request from the built-in "Send an Email" to a Visualforce page I have written. The Visualforce page then returns JSONP for the original page to use.

The setup is working fine in general. However, when an admin user has Development Mode enabled, Salesforce is injecting HTML (presumably the Development Mode bar) into the Visualforce page. This is breaking my JSONP and causing some browsers to crash when they request it.

I see a couple of possible solutions to this problem.

  • The ideal would be if there were some way to prevent Salesforce injecting this code into my Visualforce page, however I have not come across a way to do that.

  • Alternatively, I could use AJAX to check whether the user has Development Mode enabled, and if so, disable the call from the "Send an Email" page. But I can't find a way to check that either.

  • Finally, I could use AJAX to check whether the user is an Admin, and if so, disable the functionality on the "Send an Email" page. This is not ideal, as not all Admins will have Development Mode enabled.

I'd appreciate hearing your thoughts on any of these approaches.

Rob

share|improve this question
1  
For the latter one, why couldn't you just create a different home page layout for admins and remove the component that is injecting JS? –  James Loghry Mar 7 at 13:38

1 Answer 1

up vote 4 down vote accepted

You can try to use a standard SFDC User object and a field called UserPreferencesApexPagesDeveloperMode:

When true, indicates the user has enabled developer mode for editing Visualforce pages and controllers.

(Source docs)

Something like this:

    Boolean b = [Select UserPreferencesApexPagesDeveloperMode 
                 From User 
                 Where ID = :UserInfo.getUserId() 
                 Limit 1].UserPreferencesApexPagesDeveloperMode;

AJAX-only version:

function chechDevMode() {
    var currentUser = sforce.connection.query("Select UserPreferencesApexPagesDeveloperMode From User Where Id = '{!$User.Id}'");
    var records = currentUser.getArray('records');
    alert('Dev mode on: ' + records[0].UserPreferencesApexPagesDeveloperMode);
}
share|improve this answer
    
Fantastic, that's exactly what I need. Thank you mast0r. –  Rob Mar 7 at 13:37
1  
As a sidenote, Salesforce seems to be inconsistent here: the setting in My Settings > Advanced Settings is called "Development Mode", whereas the docs call it "Developer Mode". –  Rob Mar 7 at 13:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.