I've seen solutions that talk about adding control fields to allow for clever trigger branching in problems like this. I know that works, but it annoys me (feels architecturally wrong) to create such fields if it can be avoided. I've also seen solutions that have to do with using static variables for a similar purpose, but I have found occasions where one global flag is not good enough because I need the flag per record. I've tried both out and I think I want something in the middle. Something like this:

global without sharing class HeapControl {
    private static Map&lt;Id, Set&lt;String&gt;&gt; recordTags = new Map&lt;Id, Set&lt;String&gt;&gt;();
    public static void AddRecordTag(Id rowId, String tag) {
        if (recordTags.containsKey(rowId)) {
            Set&lt;String&gt; tagsForThisRow = recordTags.get(rowId);
            if (!tagsForThisRow.contains(tag)) {
                tagsForThisRow.add(tag);
            }
        } else {
            recordTags.put(rowId, new Set&lt;String&gt; { tag });
        }
    }
    public static boolean IsRecordTagged(Id rowId, String tag) {
        if (recordTags.containsKey(rowId)) {
            Set&lt;String&gt; tagsForThisRow = recordTags.get(rowId);
            if (tagsForThisRow.contains(tag)) {
                return true;
            }
        }
        return false;
    }

    @IsTest 
    public static void HeapDemo() {
        Account a = new Account(Name = 'Testing');
        insert a;
        HeapControl.AddRecordTag(a.Id, 'Control-Field-Name-1');
        a.Name = 'Testing2';
        update a;
        // A trigger that fired on Account Update could check the HeapControl for the record like this
        system.assert(HeapControl.IsRecordTagged(a.Id, 'Control-Field-Name-1'));
    }
}


I'd like a pro-con analysis of using real control fields vs mock control fields on the heap (doesn't have to be my code, anything along the lines of static Map&lt;Id, ...&gt;, if you know of a field-tested version of this code please share). 

In my not-yet-field-tested opinion, the control field concept evolved out of a workflow world, but once you decide to drop down to triggers the heap will serve you better--at least you don't have to create control fields for every little trigger branch.

I apologize this isn't standard Q&amp;A format--but this issue has been burning in my mind for months now and I think there are a lot of Salesforce developers (writing business process triggers in particular) that wrestle with this regularly. Thanks in advance for sharing your wisdom and experience!


Question: How can an Imperator Titan house a city on its shoulders when it's only 100 meters tall?
Answer: This is partially a style issue. This is a partially medium translation issue. How the Imperator Titans look in the games and how they look in the minds of artists are completely different. There are no cities on the tops of these Imperator Titans. There is often a command center where the battle can be seen and managed since they supposed to tower over the battlefield stylistically and figuratively.




This is the Imperator Class Titan figure. Most of the time there is nothing around it, so you don't know how big it is in proportion to anything else. Different sculptures emphasize different things. Some are more ornate than others and have better detail. These are some of the early designs.





The titan is often shown not alongside anything that gives it scale. The structure on the top of the shoulders of the central body has three (possibly four) guns mounted on the very top for ranged mortar fire. Some of the early paintings depicted them like this. Again, nothing really to scale it against so it can look so large…
Some artists when they cast the Imperator Titan, in the right light, with billowing smoke wafting up from the craters below, it can seem monstrously large. Just the way the God Emperor's avatar, the Imperium's most terrifying war machine should look.





But if you are from one of those Forge worlds and stylish lighting isn't going to cut it, you can compare the size of the Imperator and realize it isn't a small city of there, nor a castle, instead it is just four very large cannons mounted there. There is also a heavily shielded command center with room enough for a good deal of staff. Maybe a latte bar. A matter of style over substance. 





Here how the figures compare to the field of battle at scale. The second image shows the Imperator against the other titans at scale. Look at the teeny-tiny space marine at his feet. Remember that guy is supposed to be this guy... 





Now can you see why Imperators are supposed to be terrifying and people might be prone to exaggerate what they remember seeing? Shellshock, hysteria. This is the impression the Imperium wants to leave you with.


See Also: What makes titans so valuable in the Warhammer 40K universe?