Overlapping pseudo code

As a developer, we sometimes need to write code for checking overlapping. We check overlapping for two objects having one start and end point (Overlapping between two appointments, overlapping between two courses, programs etc).
For example lets take a Course as object, So Course has a Start Date and End Date.

Course (StartDate, EndDate).

Now we have given two courses, “courseOne” and “courseTwo”, now we need to check whether they are overlapping to each other or not?

We have For courseOne

  • courseOne.startDate
  • courseOne.endDate

For courseTwo

  • courseTwo.startDate
  • courseTwo.endDate
Analysis of Possible Overlapping

Let’s start some analysis on possible overlapping between courseOne and courseTwo, there are four possible use cases when courseOne and courseTwo can overlap each other.

Overlapping Analysis Image.
Overlapping Analysis

1.) Complete Overlap : When courseOne completely covers the courseTwo i.e. courseOne starts before courseTwo and ends after courseTwo. So in coding we can write this condition as.

2.) Under Overlap : When courseTwo completely covers the courseOne i.e. courseTwo starts before courseOne and ends after courseOne. We can simply say its vice-versa of complete overlap. In coding we can write this as.

3.) End Overlap : When ending of courseOne overlap with starting of courseTwo i.e. Before end of courseOne, courseTwo starts. We can write this check in code as.

4.) Start Overlap : When starting of courseOne is overlapped with ending of courseTwo i.e. courseOne starts before courseTwo ends. In coding we can write this conditions as.

Pseudo Code

Finally you can write a complete method to check overlapping between two object as follows.

This code can be changed as per your requirement, just grab this pseudo code and be a faster/smarter coder.
Happy Coding 🙂

setTabIcon in Service Console is not showing full icon/image.

Recently I came across service console in Salesforce, Where I need to show the tab Icon for a custom visual-force page. There is a standard method setTabIcon() , which we can use to set the tab icon. This method works fine if we have image/icon of exactly 16*16 px. But if our image/icon is larger, than its not shown completely, only some part will be shown.

So the first workaround we will think is to upload a image/icon of 16*16px. For this first we need to resize the all images/icons and then we need to upload them either on salesforce document or somewhere on net where they are publicly accessible. We need to also take care if we are in a minor release of managed package.

Analysis of Problem :

When we use setTabIcon method, it creates the below element in the HTML for showing the tab icon.

What element standard page creates is

Possible Solutions :

1.) If we can play with tab elements using javascript then we can change the span into img tag and that will resolve the issue, but for that we may face DOM exception when accessing parent element from an iframe.

2.) We can do something with setTabStyle(), that I will be using as a workaround here.

Workaround :

So instead of using setTabIcon method we can use setTabStyle method, And using that we can set the image/icon as background accordingly. See the below code snippet of apex class and visual-force page.

Here is the visual-force page code. In document ready method of jQuery (else window.onload if using only javascript) write the below method to set tab icon using setTabStyle.

I hope that will help other developer guys, if they stuck in such kind of problem. Use this workaround if it can help you to save your day.