Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I don't believe there is anything beyond Trigger.isExecuting, which simply tells you whether you are already in a trigger context or if you're coming from Visualforce, the API, or execute anonymous. </p> <p>One possible solution is to create a custom field that retains the origin of the most recent update. This can then be used to properly route logic within your triggers and avoid calling out when the last update is from your external system. Additionally you can loop through all fields in your Trigger.old and trigger.new to see which fields changed. This way you can avoid further unnecessary syncs to your external system when nothing interesting actually changed on your record (SystemTimeStamp, LastModifiedDate, etc.) Here's a sample of how to do this:</p> <pre><code>trigger ContactDescribeExample on Contact (before update) { // Get describe fields to evaluate old and new triggers with Map&lt;String, Schema.SObjectField&gt; fldObjMap = Schema.SObjectType.Contact.fields.getMap(); List&lt;Schema.SObjectField&gt; fldObjMapValues = fldObjMap.values(); // Flag to determine if field(s) other than FirstName caused this change (FirstName is just an example) Boolean hasOtherChange = false; // Loop through trigger batch for(Contact c : Trigger.new) { for(Schema.SObjectField s : fldObjMapValues) { String fldName = s.getDescribe().getName(); // Filter out fields we're not interested in if(fldName != 'FirstName' &amp;&amp; fldName != 'LastModifiedDate' &amp;&amp; fldName != 'LastModifiedById' &amp;&amp; fldName != 'SystemModstamp') { // Check to see if old and new are different if(c.get(fldName) != Trigger.oldMap.get(c.Id).get(fldName)) hasOtherChange = true; } } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload