Explore Courses Blog Tutorials Interview Questions
+1 vote
in Salesforce by (11.9k points)

Is there a way to determine if a trigger is being executed by an API call or through the Salesforce Web Interface?

I'd like to do something like this:

trigger Update_Last_Modified_By_API on My_Object__c (before update) {

    for (My_Object__c o : Trigger.New) {

        if (isAPI) {

            o.Last_Modified_By_API__c =;




(Currently using API version 25.0, though will soon be updating to 26.0)


1 Answer

+2 votes
by (32.1k points)
selected by
Best answer

There is no conventional way to in a trigger which can tell what actually might have caused an insert or update to happen. But, to achieve this, you can create a custom checkbox field on the object, something like IsAPI_c. After which you need to pass in true for that field with any API call and then check the field in your trigger for each record in the batch.

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 =; } o.IsAPI__c = false; }


Browse Categories