1

One of my standard layout button executes JavaScript as: (Only relevant lines posted)

var query = "Select id,Name from User where name ='Integration User' Limit 1"; 
var records = sforce.connection.query(query); 
var records1 = records.getArray('records');  
acc.OwnerId= records1[0].Id;

This code fails for a user belonging to some custom profile. It gives error saying "can not specify id of undefined".

But it works fine for System administrator. Clearly problem is about querying User object and access on user records.

What permission should i consider for custom profile user to give him ability to execute this SOQL.

I would not like to hard code Integration user id in JavaScript code.

5
  • What's the org wide defaults sharing settings for Users? Commented Nov 7, 2016 at 12:57
  • It's set to Private. Commented Nov 7, 2016 at 13:03
  • 2
    This might be a good use case for without sharing code if you can live with using Apex instead.
    – Adrian Larson
    Commented Nov 7, 2016 at 13:32
  • Thank you Adrian. But is it feasible to use same in ajax toolkit based Javascript code. Or calling a apex method from button would be only option. Commented Nov 7, 2016 at 13:33
  • Yes, the Ajax toolkit can allow you to access custom webservices defined in an Apex class.
    – martin
    Commented Nov 7, 2016 at 14:23

1 Answer 1

1

Here are some options:

  1. Give that profile a permission to View All Users (that's a system permission, not given on the object)

  2. Change the Sharing Settings of User to Public Read-only.

  3. Call an webservice apex method from a button, just make sure class is without sharing

  4. Save the Integration User id on a Hierarchy Custom Setting. That way you can reference it in the button and it easy to change on the future.

You must log in to answer this question.

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