Skip to content

Instantly share code, notes, and snippets.

@doppiomacchiatto
Forked from scottmcclung/TestUtility.cls
Created January 2, 2024 22:55
Show Gist options
  • Save doppiomacchiatto/7c43c8d6771289ff3249fcefc647aa33 to your computer and use it in GitHub Desktop.
Save doppiomacchiatto/7c43c8d6771289ff3249fcefc647aa33 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