After Summer15 Salesforce release, the order of elements in unordered elements (Map and Set) is always the same. Previously the order was arbitrary and as a developer, you have no control on the order.
Now as you can see, with this new feature, we are trying to order the unordered elements. A little strange to me. But if you have some code snippet, where the logic depends on the ordering of the elements, then this new feature will be really helpful.
Let’s consider the below code snippet –
If you run this code after Summer15, you will get the elements in the same order every time you execute.
21:01:19.145 (145215707)|USER_DEBUG|[10]|DEBUG|Index: 1 Employee: James
In Summer 15 release, Salesforce changed the way to calculate code coverage for multiline statements. As a developer, you feel good in some situation and bad in some situations. In this post, I will explain both the situations. Let me first explain the change – If a single statement is broken into multiple lines, then each line will be considered now while calculating the code coverage. To be more precise, each line that contains an expression will be considered while calculating code coverage. Before Summer 15 release, multiline was considered as a single line. To explain more, I will start with a simple code snippet. Situation 1 – Happy Situation: Consider the below code snippet.
Now say for example, you have written unit test methods for the methods calculateDistanceBetweenAB(), calculateDistanceBetweenBC(), calculateDistanceBetweenCD() and calculateDistanceBetweenDA(). You have also written test methods to cover line# 8,9 and 10. The only line which is not covered/tested is line# 11. Now before Summer 15 release, the way in which code overage was calculated – Total number of lines = 4 (line # 3,8,9 and 11) Total number of lines covered = 3 (line # 3,8 and 9) So the code coverage = 3/4 i.e. 75% But after Summer 15 release, the way in which code overage will be calculated – Total number of lines = 7 (line # 3,4,5,6,8,9 and 11) Total number of lines covered = 6 (line # 3,4,5,6,8 and 9) So the code coverage = 6/7 i.e. 85% As you can see that the code coverage increases here. So for me, this is a happy situation. Situation 2 – Not So Happy Situation: Consider the same code snippet.
Now say for example, you have written unit test methods for the methods calculateDistanceBetweenAB() only. You have also written test methods to cover line# 8,9 and 10. Now before Summer 15 release, the way in which code overage was calculated – Total number of lines = 4 (line # 3,8,9 and 11) Total number of lines covered = 3 (line # 3,8 and 9) So the code coverage = 3/4 i.e. 75% But after Summer 15 release, the way in which code overage will be calculated – Total number of lines = 7 (line # 3,4,5,6,8,9 and 11) Total number of lines covered = 3 (line # 3,8 and 9) So the code coverage = 3/7 i.e. 42% So this is not so happy situation as you can see that code coverage decreases here. But there is always a way. You can write more test methods to increase the code coverage. Please check the below details for your reference –
In this post, I will explain how to write unit test classes to increase test coverage for @future methods. Let’s start with a Use Case – Use Case – Let’s say in my Account object, I have a checkbox named “notifyAdmin__c” and I would like to update this checkbox for list of Accounts in a future method. Below is the Apex Class – Now let’s write the test class. Below is the test class – Here is the explanation- To test future methods, you need to simply make your future method call between Test.startTest() and Test.stopTest(). Test.stopTest() will make sure that @future method will have fired. So after Test.stopTest(), you can do all your assert.
I hope this quick example will help you to write unit test cases for your @future method. If you have any suggestion, please let me know.