I am trying to put a Javascript button in a Managed Package, but I need to check the user permissions first. Is there a code equivalent to the Schema methods for Javascript? Something like the following code but that actually works

    var namespace_prefix = 'ERIDT1__'; 
    alert("Insufficient Access."); 

This code just gives me the error: Schema is not defined

1 Answer 1


You can use sforce.connection.describeSObject, which gives you an DescribeSObjectResult, which includes the fields, and if they're createable and/or updateable. This describe result respects profile permissions.

Unfortunately, it's quite a bit of work, as you basically have to do this:

var result = sforce.connection.describeSObject('Dog__c');
var allowed = false;
result.fields.forEach(function(v) { if(v.name=='Gender__c' && v.updateable) allowed = true; });
if(!allowed) {
    alert("Insufficient access.");
} else {
    // Do what you will here

You could also use sforce.apex.execute, and call a class that returns the data you want.

  • Thank you this worked! I just had to change v.Name to v.name . Seemed to be case sensitive.
    – Jennifer
    Commented Nov 10, 2016 at 18:03
  • @Jennifer Yes, JS is case sensitive. I'll edit that for future visitors.
    – sfdcfox
    Commented Nov 10, 2016 at 18:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .