Month: April 2015

Salesforce Summer 15 New Feature || Predictable Iteration Order for Apex Unordered Collections

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: James21:01:19.145 (145338304)|USER_DEBUG|[10]|DEBUG|Index: 2 Employee: Sudipta21:01:19.145 (145498650)|USER_DEBUG|[10]|DEBUG|Index: 3 Employee: Christiaan21:01:19.145 (145587990)|USER_DEBUG|[10]|DEBUG|Index: 4 Employee: VictorSo now your Unordered Collections are also...

Read More

Salesforce Summer 15 New Feature || New way to calculate code coverage for multiline statements

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...

Read More

How to write unit test classes for @future methods

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...

Read More

Salesforce Lightning Component Framework – All you need to know to get started…

Salesforce Lightning Component framework is really awesome. This is the framework which is having Apex on the server-side and JavaScript on the client-side. In this post, I will go through few objects, functions, concepts which will be used very frequently in most of the framework. So let’s get started -Controller -Below is one controller function. It takes three parameters component, event, helper.  Controller functions are used for client-side activities. For example – behavior on button click, form submit etc. can be defined inside a controller function. When calling this functions, as a developer, you don’t need to set these parameters, the framework will populate them with the required values.Helper Functions – This is the place where you will write all your codes which will be shared between components or sub components. If you have something non-trivial logic, you should move that to helper function and let your controller call the helper function. Below is one example where I am retrieving all cases. Now to retrieve cases, I need to write SOQL and that is something happening inside Apex controller (Server-Side). So my helper function getCases is calling the Apex controller’s function and I am calling my handling function (getCases) from controller function. The advantage with this approach is that now I can call getCases whenever required from my controller. I don’t need to repeat the same login every time.Component – Lightning component is...

Read More

Earlier Posts

  • 2024 (25)
  • 2023 (47)
  • 2022 (25)
  • 2021 (35)
  • 2020 (41)
  • 2019 (13)
  • 2018 (16)
  • 2017 (14)
  • 2016 (18)
  • 2015 (74)
  • 2014 (20)