Wednesday, April 5, 2017

Real Business Data Returns

Auntie Pat Tern believes you can have your cake and eat it too, "Just use your resources wisely". So I wanted to see how to use my static resources more wisely in my Salesforce org. I have previously shown how to use static resources for test data. Now, I want to use that same data in developer sandboxes created from my org.  Since static resources are brought over like code to developer sandboxes, I can reference them in code I execute when I generate the sandboxes. Using the map datatype helps me keep relationships intact as well:

With this simple trick, I can preload my dev orgs with sample business data that I am using in my unit tests. Like Auntie Pat Tern promised, I can have my cake and eat it too when it comes to using realistic sample data in my tests and development orgs.

Whole Heaps of Fun

Auntie Pat Tern has noticed that questions about heap limits come up periodically. This could be a concern for developers needing to work with files and attachments in Salesforce. Luckily, those native objects aren't subject to typical heap limits. If you stick to blobs you can work with these large data objects. Don't use this knowledge to do bad things, now! Limits help us write code that performs well for our users as well as our fellow tenants in the multi-tenant environment we all know and love.

12:52:35:797 USER_DEBUG [43]|DEBUG|Heap: 57,789,821 / 6,000,000

Of course, if you test your code at limits, you can be sure of just how awesome your code is, which is another great reason to write thorough tests for all your code. You will find that if you are careful of what datatype you use and what you try to do with it the platform rewards you with heaps and heaps of fun.