Skip to content

Instantly share code, notes, and snippets.

@scottmcclung
Created November 20, 2017 15:41
Show Gist options
  • Save scottmcclung/b44062eb6ff7c31fa878074c5ae91543 to your computer and use it in GitHub Desktop.
Save scottmcclung/b44062eb6ff7c31fa878074c5ae91543 to your computer and use it in GitHub Desktop.
Apex method to generate fake record ids in tests.
/**
* Apex method to generate fake record ids in tests
* Created by Stephen Willcock
* https://foobarforce.com/2013/08/15/apex-method-of-the-day-string-repeat/
*/
public class TestUtility
{
static Integer s_num = 1;
public static String getFakeId(Schema.SObjectType sot)
{
String result = String.valueOf(s_num++);
return sot.getDescribe().getKeyPrefix() +
'0'.repeat(12-result.length()) + result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment