The “Five Second Rule” is, of course, a myth. If you drop a food item on the ground, the bacteria living on the ground aren’t going to wait five seconds before moving in. Besides, everything you stuff in your face is already covered with all sorts of bacteria anyway. You have an immune system, you might as well use it.

Adolphus Mannz recently gave his immune system a bit of a workout. In their SalesForce system, they needed a way to determine if a record was being added to the system or updated, and perform some slightly different logic in each case. His fellow developer came up with this rather ugly solution.

This is in SalesForce’s APEX language:

DateTime CreateDate = DateTime.valueof(proj.get('CreatedDate')) ;
DateTime timeNow = system.now();

Long createTimeSecond = CreateDate.GetTime();
Long currentTimeSecond = timeNow.GetTime();
Decimal Diff = (currentTimeSecond - createTimeSecond) ;

// Under 3000 milliseconds or 3 seconds meaning we are at creation process (Not update).
if( Diff < 3000 )
FirstTimeProjectCreation = true;

On its surface, it’s terrible. Grab the CreatedDate from a project, and then see if it was in the last three seconds. If it was, then it must be new! When we dig deeper, though, it gets worse. If a project record is being created, guess what the value of ‘CreatedDate’ is?

Null.

[Advertisement] Release! is a light card game about software and the people who make it. Play with 2-5 people, or up to 10 with two copies - only $9.95 shipped!