In our org, we are trying to block some triggers when an account is being updated through data loader.

Our strategy was to get the logginHistoryId with getCurrentSession method from the SessionManagement class. With this logginHistoryId query for that particular logginHistory and display the field Application.

Id loginHistoryId = Auth.SessionManagement.getCurrentSession().get('LoginHistoryId');
        LoginHistory loginHistory = [select Id, Application from LoginHistory where Id =: loginHistoryId];
        System.debug('Login Application: ' + loginHistory.Application);
        if (!loginHistory.Application.contains('Bulk')) {
            // Execute Trigger

If there is a mention of Bulk we would block would not execute the trigger.

This seems to work when a user logs in through the UI, but when we try it with the data loader we get this error.

System.UnexpectedException: Current session unavailable.

Is there an other way to found out if the user logged in through Data Loader?

In essence what I am trying to do is get the current session of the running user with

Id loginHistoryId = Auth.SessionManagement.getCurrentSession().get('LoginHistoryId');

with this map retrieve the LoginHistoryId and query the Application

LoginHistory logInApplication = [SELECT Id, Application FROM LoginHistory WHERE Id =: LoginHistoryId].Application

This works fine. But unfortunately when logged on through Data Loader I get the error

System.UnexpectedException: Current session unavailable.
  • We just use a dedicated user "data-migration@mycompany.com" for all data loader jobs and gate triggers and PB accordingly. – cropredy Oct 21 '19 at 15:06
  • A better solution versus one offered by the Trigger... Q&A is to use transactional security policies. In Winter '20 they released an upgraded implementation called Real-Time Event Monitoring – identigral Oct 21 '19 at 18:15

Setup > Bulk Data Load Jobs

Bulk Data Load Job

Supposing the user has the 'Bulk API' ticked in Dataloders settings, you should be able to see the jobs there.

  • I forgot to mention. We have an integration user. This user is used to execute jobs through data loader and also executes dml operation triggered from our integration with an ERP. The operations through data loader from this user should not execute the triggers. Operation triggered from our integration with the ERP should execute the Triggers.What we are trying now is through APEX Identify when this user logged in for a BULK job and when it did not log in for a bulk job in order to prevent mass trigger executions – Nyambalakesu Oct 21 '19 at 9:08

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