function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
A MeA Me 

API user cannot run query Select Id, Name From Connectedapplication, throws Fatal error.


I am developing a custom REST API for creating external identity users in Salesforce.
The API would create the user and then give access to a connected application by assigning a permission set.
The request being sent is with the connected app name. The custom API would search for the permissions sets giving access to the app(there can be more than one setup in Salesforce) , checks if the permission set in the request gives access to the app and then assigns to user.
To fetch the permission sets that give access to the app , I am using the query:
List<ConnectedApplication> apps = [SELECT Id, Name, 
                                            (SELECT Id, ParentId, Parent.Name FROM SetupEntityAccessItems)
                                            FROM ConnectedApplication
                                            WHERE Name = :appName];
appName is the connected app name sent in the API request.

The user calling the API has permissions to create user and assign permission sets, but when this query is run it  returns fatal error: "FATAL_ERROR|Internal Error" and the request fails.
According to the tests I did, any query on ConnectedApplication object is failing if its not run by an admin user. 

Is there a way to give permissions to the API user so that they can run such a query? 
I would appreciate your help.

ShivankurShivankur (Salesforce Developers) 

The field OptionsAllowAdminApprovedUsersOnly in ConnectedApp object indicates whether access is limited to users granted approval to use the connected app by an administrator. Manage profiles for the app by editing each profile’s Access list.

Please check with documentation on the object to verify if it has any behavior change with this field value change:

Hope above information helps. Please mark as Best Answer so that it can help others in future.