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.

SOQL Datetime literal in javascript for current Datetime.

Sometimes we need to use AJAX toolkit to do some SOQL/DML on Data from a custom button, which executes javascript. Here in this post we will just get current Datetime and then we will create datetime literal as per SOQL standard to fetch some records as per requirement.

For more information about SOQL date/datetime formats Click Here.

Where to Use :

This can be used when you need to fetch records where some datetime field is less/greater than current time. You can also update it to get records of last 1 hours, 2 hours etc.

Datetime Literal Javascript Methods :

Use With Ajax toolkit Salesforce :

Hope this will help when you are creating SOQL query string using javascript.

Use it wherever you can whether its javascript button, lightening component or anything, to save your time and be a speedy coder.

Disable Inline Editing on Apex:EnhancedList through jquery script

Sometimes we don’t want to keep inline editing on the apex:enhancedList, and unfortunately there is no standard way to disable inline editing. But there is always a solution for , not a standard way but we can say workaround to fulfill the requirement.

Here is the jQuery code snippet which can be put in a javascript function and then we can call this function on the “oncomplete” attribute of apex:enhancedList. Its obvious that you must include jQuery files for the execution of the below code snippet.