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'); if(!isXYZIntegrationUser) // 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 }