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?

2
  • Lightning, Visualforce, static resource? Commented Dec 9, 2016 at 7:17
  • @sfdcfox for object custom button javascript Commented Dec 9, 2016 at 7:25

1 Answer 1

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);
}
1
  • can we use Global variable instead of query? Commented Dec 9, 2016 at 10:20

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.