-Поиск по дневнику

Поиск сообщений в rss_thedaily_wtf

 -Подписка по e-mail

 

 -Постоянные читатели

 -Статистика

Статистика LiveInternet.ru: показано количество хитов и посетителей
Создан: 06.04.2008
Записей:
Комментариев:
Написано: 0


CodeSOD: The Three Second Rule

Вторник, 05 Апреля 2016 г. 13:30 + в цитатник

The Five Second Rule is, of course, a myth. If you drop a food item on the ground, the bacteria living on the ground arent 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 SalesForces 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, its 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!

http://thedailywtf.com/articles/the-three-second-rule

Метки:  

 

Добавить комментарий:
Текст комментария: смайлики

Проверка орфографии: (найти ошибки)

Прикрепить картинку:

 Переводить URL в ссылку
 Подписаться на комментарии
 Подписать картинку