function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
myforcedotcommyforcedotcom 

determine what caused trigger to occur

Is there a way to determine if a trigger on a Contact was caused by someone clicking the Save button on a page, or if an insert / update came from an API call from an app like Outlook?

 

 

thanks for your help.

TehNrdTehNrd

Ya, in the debug log for that user is should display what operation invoked the trigger. Only issue is you have to manually setup the debug logs for each user and then they only track 20 transactions.

myforcedotcommyforcedotcom

I'm sorry I wasn't totally clear in my original post.

I want to be able to determine if the insert/update came from a SFDC UI or API Call programatically in the trigger at runtime.

I want to do certain things if the upsert came from the SFDC UI and something different if it comes via an API call.

 

 

sfdcfoxsfdcfox

You can't tell what the source of the trigger was. The system is not designed to support that level of detail. You can check for Trigger.new.size() == 1, where 1 means it was "likely" a UI transaction, and otherwise "likely" means it was an API transaction or import wizard. However, even those are not foolproof methods (i.e. a batch of 201 records would be 200 records plus 1 record, and Outlook Connector might synchronize only 1 record).

 

Use Visualforce when possible if you want to make "UI-only" features, and use triggers when you want the logic to always be enforced. You can use a sort of "trap door" mechanism to supress triggers when running Visualforce pages by making a static variable that the trigger checks before continuing execution.