Skip to main content
Ken Linder 님이 #Data Management에 질문했습니다
Here is the situation:

 

We have a trigger that uses SOQL.  It is intended to fire when changes are made to Leads from the UI.  It works fine.   We have a scheduled job that updates thousands of leads at one time.  That causes the trigger to fire and thus the scheduled job fails due to governor limits.

 

Is there a way using the UserInfo object in the trigger to determine if the currently running user is 'system'?  If I can determine this in the trigger, then I can bypass all the trigger logic and not exceede the governor limits.

 

And...  Am I correct in assuming the Scheduled Jobs are running as System?
답변 1개
  1. 2014년 10월 2일 오후 4:37
    I have the answer; sort-of.  I bypass the trigger logic by checking if Userinfo.getSessionID() != null

     

    If this is true, then a UI user is making a change  If Userinfo.getSessionID() is NULL, then the change came from a scheduled job.

     

    As a note, while developing the code for a scheduled job, using the Developer Console to run a class will make getSessionID() return a valid session ID.
0/9000