I created connected apps for various integrated systems in our landscape, that use custom developed REST endpoints to access specific data from our salesforce org.

I have separate apps per system, and since I have a logging application that logs any calls to my API with some meta-data (duration, execution start/end timestamps, outcomes, errors, used ressource path, etc), I would like to also log the connected app that was used to authenticate.

I already searched the Auth Namespace but could not find any method to retrieve the ConnectedAppId, is there a way to get this information?


You can query connected app information with the help of following query:

Select Name, Id From ConnectedApplication


You can extend Auth.ConnectedAppPlugin to log through which connected app you performed authentication.

Here is sample code:

global with sharing class TestConnectedAppPlugin extends Auth.ConnectedAppPlugin {

    global override boolean authorize(Id userId, Id connectedAppId, boolean isAdminApproved) {


You need to add this class in the Edit Policies section of Connected app.

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.