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


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 Nov 10 '16 at 18:03
  • @Jennifer Yes, JS is case sensitive. I'll edit that for future visitors. – sfdcfox Nov 10 '16 at 18:05

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.