Ye Meri Life Hai - Chirag Mehta

Be Good & Do Good!

Page 2 of 133

Javascript (jQuery) code to fetch Salesforce Lead Convert Custom Field Mappings (in terms of API Names)

Yesterday came across a requirement to list down Lead Convert Custom Field Mappings in terms of API Names ie Lead Field1__c maps to Account/Contact/Opportunity Field1__c. Salesforce UI doesn’t give that option to extract same. Neither any metadata API got that, really strange that there’s no way I can extract Lead Convert Custom Field Mappings (in terms of API Names). Is there any? please help in case I’m missing some standard way of extracting that out?

Easiest option could have been that I sit down and do manual and tedious way of reading each field label finding its API Name and record the same in excel, but this doesn’t seem viable option for an org with 100+ lead convert field mappings. As I couldn’t find one using all standard approaches, I started thinking of wicked ways of achieving it. And as usual Javascript (jQuery) comes to rescue party!

Login to Salesforce Org in Chrome or FF Browser,
Navigate to lead convert field mappings page (Select Your Name | Setup | Customize | Leads | Fields | Map Lead Fields),
Open Javascript Console,
Now load jQuery first (you can do same by loading any existing jQuery booklet or userscript too) by executing below code in JS Console.


var jq = document.createElement('script');
jq.src = "//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);
$j=jQuery.noConflict();

Now comes the main code which will output LeadFieldAPIName, Account/Contact/Opportunity Field APIName, Account or Contact or Opportunity. Execute below code too in JS Console.

//Traverse across all Select elements
$j("select").each(function () {

//Consider only the ones with a mapping selected
if (this.value != '') {

//Fetch Object Name to which this particular Lead field is mapped, whether its Account or Contact or Opportunity
var objectname = $(this).find('option:selected').text().split(".")[0];

//Tricky Part : As this lead convert field mappings page doesn’t store Lead field API Names, it only contains lead field ID (15 digit SFDC ID) so we will have to do AJAX request of LEAD field detail webpage to fetch LEAD API Name corresponding to lead field ID
var contentText = $.ajax({url: "/" + this.name,async: false}).responseText;

//In fetched content, search and extract field API Name
var fromfield = $(contentText).find('td').filter(function () {
return $(this).text().indexOf('API Name') === 0;
}).closest('td').next().html();

//Similarly AJAX request for Account/Contact/Opportunity field detail page to fetch respective field API Name
contentText = $.ajax({url: "/" + this.value,async: false}).responseText;

//In fetched content, search and extract field API Name
var tofield = $(contentText).find('td').filter(function () {
return $(this).text().indexOf('API Name') === 0;
}).closest('td').next().html();

//Output LeadAPIName, Account/Contact/Opportunity APIName, Account or Contact or Opportunity
console.log(fromfield + ',' + tofield + ',' + objectname);

}});

Please Note:

  • This isn’t most neat and recommended way, so if you come across something really clean and less network consuming solution please share your solutions in comments below
  • I’m not an expert in jQuery, so there might be obvious and recommended ways of coding jQuery and my above coding might sound nascent way of handling jQuery, so please ignore my lack of knowledge around jQuery and help me to optimize same.
  • Fetching Lead/Account/.. Field API Name from Field ID might be done using other ways too (describe API Calls?), but thought of doing it in just one script, so did that using AJAX calls and parsing retrieved webpage content
  • As always, feedback/suggestions are always welcome

Auto-Refresh Salesforce Dashboard every 5, 10 or 15 … seconds, minutes or hours …

UPDATE (7 Oct 2014) : This is now available in form of chrome extension, Try it out @ AppExchange or https://chrome.google.com/webstore/detail/auto-refresh-salesforce-d/mogildlgjglckdcfclpbcbidpdkjgeeb or http://satrangtech.com/products.htm#5

Is there a way we can have Salesforce Dashboard Auto-Refresh every few seconds (not recommended) or every x minutes or every x hours …?

Standard Out of box functionality does allow to refresh dashboard, but the lowest level of refresh interval is DAILY or WEEKLY or MONTHLY.

Lets say you want to have(display) a Sales Monitor always LIVE showing real time data, how do you achieve that?

There’s no direct way of doing it, but JS (as always) comes to the rescue …

  1. Log in to Computer (which is streaming output to LIVE monitor) , open Chrome browser (will try to update the script later to make it work in all browsers)
  2. Login to Salesforce and Navigate to desired Dashboard
  3. Delete url from  address/url bar, type (or copy+paste) below code and hit enter in address/url bar. (Make sure javascript: at start is there, chrome does remove it when copy pasted)

    javascript:function autorefresh() {document.getElementById('refreshButton').click();setTimeout(autorefresh, 5000);}autorefresh();

  4. Now do a full screen and enjoy Dashboard Live Monitor 🙂

 Please Note:

  1. 5000 represents 5000 milli seconds ie 5 seconds, so change the same according to your requirements ie if you want it to refresh every minute change the value to 60000
  2. This is not a recommended way, as its a tweak and might not work in future. (But as of now its working great and helps in having real time monitor of your favorite dashboard, so enjoy!)

Might be this can be an admin tool or a chrome extension, will try to make one when I get time and chance 🙂

I’ll carry you out every morning until death do us apart …

Today I came across a really nice story, which touched my heart. This probably is story of every next door in these modern days of relationship where relations are not being respected or cared for.

When I got home that night as my wife served dinner, I held her hand and said, I’ve got something to tell you. She sat down and ate quietly. Again I observed the hurt in her eyes.
Suddenly I didn’t know how to open my mouth. But I had to let her know what I was thinking. I want a divorce. I raised the topic calmly. She didn’t seem to be annoyed by my words, instead she asked me softly, why?

I avoided her question. This made her angry. She threw away the chopsticks and shouted at me, you are not a man! That night, we didn’t talk to each other. She was weeping. I knew she wanted to find out what had happened to our marriage. But I could hardly give her a satisfactory answer; she had lost my heart to Jane. I didn’t love her anymore. I just pitied her!

With a deep sense of guilt, I drafted a divorce agreement which stated that she could own our house, our car, and 30% stake of my company. She glanced at it and then tore it into pieces. The woman who had spent ten years of her life with me had become a stranger. I felt sorry for her wasted time, resources and energy but I could not take back what I had said for I loved Jane so dearly. Finally she cried loudly in front of me, which was what I had expected to see. To me her cry was actually a kind of release. The idea of divorce which had obsessed me for several weeks seemed to be firmer and clearer now.

The next day, I came back home very late and found her writing something at the table. I didn’t have supper but went straight to sleep and fell asleep very fast because I was tired after an eventful day with Jane. When I woke up, she was still there at the table writing. I just did not care so I turned over and was asleep again.

In the morning she presented her divorce conditions: she didn’t want anything from me, but needed a month’s notice before the divorce. She requested that in that one month we both struggle to live as normal a life as possible. Her reasons were simple: our son had his exams in a month’s time and she didn’t want to disrupt him with our broken marriage.

This was agreeable to me. But she had something more, she asked me to recall how I had carried her into out bridal room on our wedding day. She requested that every day for the month’s duration I carry her out of our bedroom to the front door ever morning. I thought she was going crazy. Just to make our last days together bearable I accepted her odd request.

I told Jane about my wife’s divorce conditions. . She laughed loudly and thought it was absurd. No matter what tricks she applies, she has to face the divorce, she said scornfully.

My wife and I hadn’t had any body contact since my divorce intention was explicitly expressed. So when I carried her out on the first day, we both appeared clumsy. Our son clapped behind us, daddy is holding mommy in his arms. His words brought me a sense of pain. From the bedroom to the sitting room, then to the door, I walked over ten meters with her in my arms. She closed her eyes and said softly; don’t tell our son about the divorce. I nodded, feeling somewhat upset. I put her down outside the door. She went to wait for the bus to work. I drove alone to the office.

On the second day, both of us acted much more easily. She leaned on my chest. I could smell the fragrance of her blouse. I realized that I hadn’t looked at this woman carefully for a long time. I realized she was not young any more. There were fine wrinkles on her face, her hair was graying! Our marriage had taken its toll on her. For a minute I wondered what I had done to her.

On the fourth day, when I lifted her up, I felt a sense of intimacy returning. This was the woman who had given ten years of her life to me. On the fifth and sixth day, I realized that our sense of intimacy was growing again. I didn’t tell Jane about this. It became easier to carry her as the month slipped by. Perhaps the everyday workout made me stronger.

She was choosing what to wear one morning. She tried on quite a few dresses but could not find a suitable one. Then she sighed, all my dresses have grown bigger. I suddenly realized that she had grown so thin, that was the reason why I could carry her more easily.

Suddenly it hit me… she had buried so much pain and bitterness in her heart. Subconsciously I reached out and touched her head.

Our son came in at the moment and said, Dad, it’s time to carry mom out. To him, seeing his father carrying his mother out had become an essential part of his life. My wife gestured to our son to come closer and hugged him tightly. I turned my face away because I was afraid I might change my mind at this last minute. I then held her in my arms, walking from the bedroom, through the sitting room, to the hallway. Her hand surrounded my neck softly and naturally. I held her body tightly; it was just like our wedding day.

But her much lighter weight made me sad. On the last day, when I held her in my arms I could hardly move a step. Our son had gone to school. I held her tightly and said, I hadn’t noticed that our life lacked intimacy. I drove to office…. jumped out of the car swiftly without locking the door. I was afraid any delay would make me change my mind…I walked upstairs. Jane opened the door and I said to her, Sorry, Jane, I do not want the divorce anymore.

She looked at me, astonished, and then touched my forehead. Do you have a fever? She said. I moved her hand off my head. Sorry, Jane, I said, I won’t divorce. My marriage life was boring probably because she and I didn’t value the details of our lives, not because we didn’t love each other anymore. Now I realize that since I carried her into my home on our wedding day I am supposed to hold her until death do us apart. Jane seemed to suddenly wake up. She gave me a loud slap and then slammed the door and burst into tears. I walked downstairs and drove away. At the floral shop on the way, I ordered a bouquet of flowers for my wife. The salesgirl asked me what to write on the card. I smiled and wrote, I’ll carry you out every morning until death do us apart.

That evening I arrived home, flowers in my hands, a smile on my face, I run up stairs, only to find my wife in the bed – dead. My wife had been fighting CANCER for months and I was so busy with Jane to even notice. She knew that she would die soon and she wanted to save me from the whatever negative reaction from our son, in case we push through with the divorce.— At least, in the eyes of our son—- I’m a loving husband….

The small details of your lives are what really matter in a relationship. It is not the mansion, the car, property, the money in the bank. These create an environment conducive for happiness but cannot give happiness in themselves.

So find time to be your spouse’s friend and do those little things for each other that build intimacy. Do have a real happy marriage!

Happy Diwali to you & your family!

Festival of lights … togetherness … happiness … prosperity … sweets … celebrations … Yes Diwali is here..

A festival which is celebrated with gaiety by people of every religion. Its magical and radiant touch creates an atmosphere of joy and festivity.

With fullest of enthusiasm and excitement we all welcome this festive season together wishing Happy Diwali to you & your family.

Bid Adieu Jardine Lloyd Thompson!

Dear Friends and Colleagues,

Yesterday brought the beginning, tomorrow brings the end, and somewhere in between I acquired one of the best experiences of my life!

As some of you already know, today is my last day at JLT. Almost 15 months!!!

I have thoroughly enjoyed every aspect of my tenure here and would like to sincerely thank each JLT’ian for the experiences shared, friendships made, opportunities offered and good times spent. This has been a sojourn of both professional and personal augmentation and I am sure every time I reminisce about these days, it would bring a smile on my face.

Fate ordains that every good thing must end for another beginning. So with mixed feelings, I bid you goodbye and good luck as I move on to a new phase of my career.

Thank you,
Chirag Mehta

May all living beings grant me forgiveness … Michhami Dukkadam

On this auspicious occasion of Jain Paryushan festival, I (and my family) wish you all:

Michhami Dukkadam (My bad deeds be fruitless/forgiven)

Khaamemi Savve Jeeva (I grant forgiveness to all living beings)
Savve Jeeva Khamntu Me (May all living beings grant me forgiveness)
Metti Me Savve Bhuyeshu (My friendship is with all living beings)
Vairam Majham NA Kenai (My enemy is totally non-existent)

I forgive (from the bottom of my heart without any reservation) all living beings (who may have caused me any pain and suffering either in this life or previous lives), and I beg (again from the bottom of my heart without any reservation) for the forgiveness from all living beings (no matter how small or big to whom I may have caused pain and suffering in this life or previous lives, knowingly or unknowingly, mentally, verbally or physically, or if I have asked or encouraged someone else to carry out such activities). (Let all creatures know that) I have a friendship with everybody and I have no revenge (animosity or enmity) toward anybody.

Yours,
Chirag Mehta & Family

Salesforce Data Storage – 2100 % Used – Whack!!!

Today I was doing data load (via some tool) and I was able to do data load of 420 MB, though my (or any) developer org allowed limit is 20 MB, Isn’t that strange!

I understand Salesforce does allow to store certain % beyond allowed limit, but this is almost 21 times allowed limit – sounds really whacky!

This is like hitting nail 21 times hard then allowed hit limit. Hope Salesforce Storage is not screaming 🙂

Chatter Stream or Chatter Ticker …

We have this amazing thing of collaboration inside Salesforce, the Chatter – an amalgamation of best features of Facebook and Twitter.  And to add, it’s for enterprise, so its Enterprise Collaboration Isn’t that awesome!!! Chatter supports lot of things post, comments, likes, follows etc and  best part is its not just user posts, comments etc .. its data posts, comments etc i.e., even the data is part of the collaboration . That adds to awesomeness!

However, there’s been one feature which I been waiting for and always wanted to see which is auto refresh of posts (for techies – ajax refresh) without need to refresh the entire page. Without this feature collaboration doesn’t seems to be complete and web2.0 type.  An alternative to auto refresh can be a stream or ticker (like we have Feed Ticker on facebook) which keeps scrolling and shows posts / comments happening around without need to refresh page.

So I thought of building the same, and first thing I needed was a poller which can poll and see if there are any chatter posts, but that would have been too resource intensive, and would have died after few hours because of governor limits and bla … bla … And to save me, there came a really great feature The Streaming API. I’m loving it!

Two lines about API – Use Streaming API to receive notifications for changes to Salesforce data that match a SOQL query you define in a secure and scalable way. Streaming API is useful when you want notifications to be pushed from the server to the client based on criteria that you define.

So what’s next, I was super excited to get all started to use Streaming API and poll Chatter objects.  I was able to get basic streaming API program working (after few discussions around streaming api with Pat Patterson, as the API had few issues in terms of documentation).

In basic example, I created a PushTopic (a SOQL query that you want notifications about) of Account. Now as the objective is chatter stream, so I tried to create a PushTopic around chatter object, and here was entry of the Villain – PushTopic aren’t supported yet for Chatter objects (SF please enable the same @ earliest)

So what next,  trigger the rescue man came to help. Developed few triggers which will do realtime snapshot of chatter objects, and then created push topic against these snapshot objects.  This way (though indirect way) I will be able to get push notifications (using streaming API)  of chatter posts…wow, finally I made it. I got the CHATTER STREAM or CHATTER TICKER ..

The use case of this is endless,  sky is not the limit..

ChatterTicker

Road map:

  • The notifications are lost the moment page is reloaded, so will try to add something which makes them persist until user has seen them.
  • Apply Sharing Settings, as currently all messages of  all users are shown

Trust me this idea struck me in morning and by evening the tool/app was ready. Thanks to Rajesh Shah for helping me out in testing this app.

 

Make Salesforce calendar year drop-down to show earlier years

Problem:
The birthdate field on the Contact object doesn’t show previous year and neither does it allow to switch back and forth the Years part easily.

Solution:
Below example will show the last 100 years.

  1. Go to Setup -> App Setup -> Customize -> User Interface. Here make sure the ‘Show Custom Sidebar Components on All Pages’ is checked.
  2. Go to Setup -> App Setup -> Home Page Layouts. Make sure all your Home Page Layouts have the Messages & Alerts component checked.
  3. Go to Setup -> App Setup -> Home Page Components. Here, click edit for Messages & Alerts. In the textarea, copy and paste the javascript code below and save (it can just go below your normal Messages & Alerts, won’t show up on the actual page).
<script src="/js/dojo/0.4.1/dojo.js"></script>
<script src="/soap/ajax/11.1/connection.js" type="text/javascript"></script>
<script type="text/javascript">
dojo.require("dojo.collections.Store");
dojo.require("dojo.charting.Chart");
dojo.require('dojo.json');
var arYears = getYears();
function swapYears(){
	if(document.getElementById('calYearPicker') != null) {
		var select = document.getElementById('calYearPicker');
		var curValue = select.value;
		var parentx = select.parentNode;
		parentx.removeChild(select);
		select = document.createElement('select');
		select.size = 1;
		select.id = 'calYearPicker';
		select.name = 'calYearPicker';
		parentx.appendChild(select);
	}
	if(select != null) {
	for(x=0;x<100;x++) {
		select.options[x] = new Option(arYears[x], arYears[x], false, false);
	}
	}
}
function getYears() {
	sforce.sessionId = getCookie('sid');
	sforce.connection.sessionId=sforce.sessionId;
	var out = [];
	var currentTime = new Date()
	var year = currentTime.getFullYear()
	try {
		for(x=0;x<100;x++) {
			out[x] = x+year-99;
		}	

	} catch(error) {
		alert(error);
	}
	return out;
}
dojo.addOnLoad(swapYears);
</script>

Credits: Salesforce Community (http://boards.developerforce.com/t5/General-Development/Date-of-Birth-field-Calendar-years-don-t-go-back-before-this/td-p/120133)

Email to Chatter

Installation Url: https://login.salesforce.com/packaging/installPackage.apexp?p0=04t30000001EoJh

« Older posts Newer posts »