Skip to content

Instantly share code, notes, and snippets.

@zaki-yama
Last active August 29, 2015 14:14
Show Gist options
  • Save zaki-yama/d64ee57be887ebbfab32 to your computer and use it in GitHub Desktop.
Save zaki-yama/d64ee57be887ebbfab32 to your computer and use it in GitHub Desktop.
CreatedDateでのソートはアテにならない
@isTest
public class CreatedDateTest {
public static testMethod void run() {
Account a = new Account();
a.Name = 'Account # 1';
insert a;
System.debug(LoggingLevel.INFO, 'A\'s id: ' + a.id);
Account b = new Account();
b.Name = 'Account # 2';
insert b;
System.debug(LoggingLevel.INFO, 'B\'s id: ' + b.id);
// assertion
Account result = [SELECT Id FROM Account ORDER BY CreatedDate DESC LIMIT 1];
System.debug(LoggingLevel.INFO, 'Result\'s id: ' + result.id);
System.assertEquals(b.id, result.id); // FAIL
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment