[SalesForce] Rest API SOQL Query Malformed

I'm trying this SOQL query in the REST Explorer:

/services/data/v39.0/query/?q=SELECT+AssigneeId+PermissionSet.Id+Assignee.Name+PermissionSet.Name+PermissionSet.Label+FROM+PermissionSetAssignment+WHERE+PermissionSet.Id=[AN ID]

[AN ID] is formed like '0000'

It's saying that it's malformed at Assignee.Name.

I don't know where I'm going wrong with this query as it works in the developer console.

Best Answer

Your fields must be comma delimited. If you were to run the query listed in your URL in the Developer Console, it would translate to:

SELECT AssigneeId PermissionSet.Id Assignee.Name PermissionSet.Name PermissionSet.Label
FROM PermissionSetAssignment WHERE PermissionSet.Id='0000'

Of course this query will not work. The properly delimited query would be:

SELECT AssigneeId, PermissionSet.Id, Assignee.Name, PermissionSet.Name, PermissionSet.Label
FROM PermissionSetAssignment WHERE PermissionSet.Id='0000'

And the properly formed URL would be:

q=SELECT+AssigneeId,PermissionSet.Id,Assignee.Name,PermissionSet.Name,PermissionSet.Label+FROM+PermissionSetAssignment+WHERE+PermissionSet.Id='0000'

Note that the SOQL Developer Guide makes this point clear in SOQL SELECT Syntax (emphasis mine):

Syntax
fieldListsubquery

Description
Specifies a list of one or more fields, separated by commas, that you want to retrieve from the specified object. The bold elements in the following examples are fieldlists:

SELECT Id, Name, BillingCity FROM Account
SELECT count() FROM Contact
SELECT Contact.Firstname, Contact.Account.Name FROM Contact

You must specify valid field names and must have read-level permissions to each specified field. The fieldList defines the ordering of fields in the query results.

fieldList can include a subquery if the query traverses a relationship. For example:

SELECT Account.Name, (SELECT Contact.LastName FROM Account.Contacts)
FROM Account

The fieldlist can also be an aggregate function, such as COUNT() and COUNT(fieldName), or be wrapped in Translating Results.

Related Topic