+ Start a Discussion
yajivyajiv 

Access the foreign key ProfileId in User using the REST API and SOQL query

 

Hi,
I am trying to access the foreign key ProfileId in User using the REST API but I get an error on the ProfileId. How do I get the ProfileId for the User using the SOQL query below for the REST calll to the User? I have already logged in and am passing the accessToken as the Authorization Header.
HttpClient httpclient = new HttpClient();
GetMethod get = new GetMethod("https://" + instanceUrl
+ "/services/data/v20.0/query");
// set the token in the header
get.setRequestHeader("Authorization", "OAuth " + accessToken);
// set the SOQL as a query param
NameValuePair[] params = new NameValuePair[1];
//WHERE IsActive = true 
params[0] = new NameValuePair("q",
"SELECT Email,Id,ProfileId FROM User LIMIT 1");

 

TIA,
Vijay

 

Pat PattersonPat Patterson

Hi Vijay,

 

What error are you seeing (HTTP status/content)? Do you see the same error if you omit ProfileId? Are you sure that your test user has permission to view ProfileId?

 

I just ran the same query from a PHP test script and it works fine (reformatted for clarity):

 

 

{
"totalSize":1,
"done":true,
"records":[
{
"attributes":{
"type":"User",
"url":"/services/data/v21.0/sobjects/User/005T00000017eSjIAI"
},
"Email":"user@example.com",
"Id":"005T00000017eSjIAI",
"ProfileId":"00eT0000000izuxIAA"
}
]
}

 

 

Cheers,

 

Pat

SuperfellSuperfell

IIRC, ProfileId will only be available if your user has view setup (and therefore can see profiles)