This question already has an answer here:

I have an Apex Job that is being triggered from an 'afterInsert' trigger, but I don't want that Job to be executed if the insert is being performed by a specific external application. I just need to know the Connected App Id that triggered the action, so I can skip the execution of the Job in case the Insert is coming from this specific app, but the only thing I can see is some information about the authSession (LoginType and SessionType) and the UserInfo, but nothing regarding the Connect App used.

Any idea how can I get this information?

Thanks in advance.

marked as duplicate by Pranay Jaiswal, battery.cord, glls, Reshma, Sebastian Kessel Feb 9 at 18:28

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


You can utilize either a Custom Permission or a Custom Integration Profile in this case without the need of finding out the connected app details.

Using Custom Permission

In case if you plan to use the same profile, across different external users, then utilize a Custom Permission and assign to specific Users. Using this approach, you can also mention the specific Connected App for which this permission is applicable. This way you will always know that Users having this Custom permission are always associated to that connected app. You can then utilize this custom permission for any conditional check within your code.

Let's say, if you have a custom permission XYZ_External_App assigned to the User, then you can just use the custom permission to verify the check in your code.

Boolean isXYZIntegrationUser = FeatureManagement.checkPermission('XYZ_External_App');
    // perform execution only if the user does not have the custom permission

Using Custom Profile

Usually with any integration scenarios, a good idea is to create a custom Integration profile. Let's say if you create a custom profile named "Integration User", you can then in your trigger logic, just verify if the executing user's profile is that of "Integration User", then do not execute the logic.

String name = [select name from profile where id = :UserInfo.getProfileId()].name;
if(!'Integration User'.equals(name)) {
    // perform execution only if the user is not on integration profile

I don't know of any way to get the Connected App that's triggered a DML action, but if the app's authenticating with a specific set of user credentials (and those credentials are unique to this Connected App) then you could filter using 'System.UserInfo.getUserId()', or some other unique identifier from the User's Info (Link to SF docs on UserInfo Class).

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