There is currently no standard way to report in a trigger what actually caused an update or insert (API, standard page layout, VF page and controller, some other Apex code, etc.). Here is a complete list of trigger context variables .
To achieve this, I would suggest creating a custom check box for the object, something like IsAPI__c (with a default value of false ). Then you will need to go through true for this field with any API call, and then check the field in the trigger for each entry in the package (just make sure you remember that reset is false when you make subsequent calls from user interface are not considered as API calls).
trigger Update_Last_Modified_By_API on My_Object__c (before update) { for ( My_Object__c o : Trigger.New ) { if ( o.IsAPI__c ) { o.Last_Modified_By_API__c = datetime.now(); } o.IsAPI__c = false; } }
source share