1

I read here that we can access ObjectType from Global Variable.I want to check if the user able to edit Account using updateable .But how to write it?

I tried this

  {!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
    console.log('@Test  ==='+{!$ObjectType.Account.updateable});

It throw me this error.

Error: Field updateable does not exist. Check spelling.

So I copy paste this just to test

{!$ObjectType.Account.fields.Name.Label}

Also it throw me error.

Error: Field Account.fields.Name.Label does not exist. Check spelling.

What is the correct way to use Global Variable in Javascript?

  • Lightning, Visualforce, static resource? – sfdcfox Dec 9 '16 at 7:17
  • @sfdcfox for object custom button javascript – unidha Dec 9 '16 at 7:25
1

To know whether user can edit the record you can Query UserRecordAccess object. You will get all the details as below.

{!REQUIRESCRIPT("/soap/ajax/33.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/33.0/apex.js")}

var result = sforce.connection.query("SELECT RecordId, HasReadAccess, HasEditAccess, HasDeleteAccess FROM UserRecordAccess WHERE UserId = '{!$User.Id}' AND RecordId = '{!Account.Id}'", {onSuccess : success, onFailure : failure});
function success(result) {
    var records = result.getArray("records");
    if(records[0]){
        var accessdetail = records[0];
        console.log("HasDeleteAccess = "+accessdetail.HasDeleteAccess);
        console.log("HasEditAccess = "+accessdetail.HasEditAccess);
        console.log("HasReadAccess = " + accessdetail.HasReadAccess);
    }
}
function failure(error) {
    console.log("An error has occurred " + error);
}
  • can we use Global variable instead of query? – unidha Dec 9 '16 at 10:20

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.