I was at dreamforce this year and I saw a session on testing and have looked online everywhere to try to find this trick the guy did. He was creating sObjects to complete dependencies of other sObjects but he did not insert these into the database. All of the objects were only in memory and he created fake IDs so that he could still link objects together and run his code that used IDs to operate on.

This would be huge for me to not have to insert into the database and run all my trigger code that has already been tested. Right now I have a test factory implemented that creates my objects and their dependencies and passes them to subsequent test methods but this is a really coupled design. Being able to do this small trick would allow me to create objects that I need completely in memory, increasing run time and making it much easier to test logic that relies on a large number of related objects.

I have tried a couple things like creating a UserRole Id by prefacing the Id with 00E and then 12 more random letters/numbers and also 15 more random letters and numbers. Maybe there is more depth to the Id field that I am missing. Any help with this would be greatly appreciated.

1 Answer Live amp; Play On Breaking Apps Google – Alerts News Fox News Video 1


Here's the fake ID test utility method as used in my DF13 "Tests and Testability" session:

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; } }

Originally posted here: http://foobarforce.com/2013/08/15/apex-method-of-the-day-string-repeat/

And here is a use of it:

Account a Video Live News Apps Breaking Alerts Play News On Google Fox – amp; = new Account(Id=TestUtility.getFakeId(Account.SObjectType)); Opportunity o On Google Video News Live Alerts amp; Breaking Play News Apps Fox – = new Opportunity(AccountIdOf Find Doctor A University Jacksonville Uf Health Florida qPC1qaw=a.Id);

Your Answer

  • Apps Live Video News Google Play Fox – On News Breaking amp; Alerts

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.