Free JQuery Mobile Adoption Manager JavaScript Code

Written by ShamrockCRM on August 26, 2012 – 9:03 pm

This is Part 3 in the series of Salesforce.com HTML5 Mobile Development using VisualForce, APEX, JavaScript (JQuery Mobile) and HTML5.  I have already posted the code for the Visualforce as well as the APEX Controller.  This part in the series provides you with the JavaScript code to finalize everything.  The combination of all of this will show you how to implement this Adoption Manager AppExchange app for managing the adoption of your users.

A couple of notes here.  This code is certainly not optimized and certainly not prettied up.  A lot of the functions need to be merged into cleaner functions.  The memory usage could probably optimized a little better.  There are a couple of other things to play with as well.  This is basically a way to help you learn how to implement different features using Salesforce.com in HTML5 with JQuery mobile, such as querying profiles and dynamically populating a form picklist and displaying lists of users on the screen and activating/deactivating users, etc.  Take what you will from this, but it is a fully functional mobile app for you to hack and place into PhoneGap if you would like.

Salesforce JQuery Mobile

This code goes into the usermanager.resource static resource (after the break).
Read more »


Tags: , , , , , , , ,
Posted in Salesforce Mobile, VisualForce, Web Development | Comments Off on Free JQuery Mobile Adoption Manager JavaScript Code

Salesforce.com JavaScript to Override Buttons

Written by ShamrockCRM on July 23, 2009 – 7:20 pm

This little snippet of code is written in JavaScript.  This piece of code is simply an example of what you can do by embedding JavaScript into a custom Salesforce.com button.

In this example, we have Opportunities and a related custom object called Shipments.  You sell a Product and you ship it, get it?

This button would be displayed on the “Shipments” related list on an Opportunity.  The button would be titled “New Shipment” and would replace the default button.

This button would check if a shipment for this Opportunity is currently “In Progress” and not “Shipped”.  If so, it will not allow the user to create a new shipment.  They should combine this new shipment into the existing one to save on transportation costs.

{!REQUIRESCRIPT("/soap/ajax/15.0/connection.js")} 

var result = sforce.connection.query("Select Id From Shipment__c where Status__c = 'In Progress' and Opportunity__c = '{!Opportunity.Id}' ");
var records = result.getArray("records"); 

//If there are no Shipments In Progress, redirect the User to the New Shipment page
if (records.length == 0){
window.parent.location.href="{! urlFor( $Action.Shipment__c.New, $ObjectType.Job__c,null,true)}&CF00N20000001B5jC_lkid={!Opportunity.Id}&CF00N20000001B5jC={!Opportunity.Name}";
}
//If there are Shipments In Progress for this Opportunity
else{
alert("There is a current job on the system - please complete this job prior to creating a new job");
}

Tags: , , , ,
Posted in S-Controls, Salesforce.com, Web Development | Comments Off on Salesforce.com JavaScript to Override Buttons

Populate Custom Lookup Fields from an S-Control

Written by ShamrockCRM on April 4, 2009 – 12:00 pm

Probably the most common request I receive from clients is to automatically populate a new record with fields.  This is a simple process, usually involving an S-Control and some URL parameters.  It gets a little more complicated, however, when you start wanting to populate lookup fields on the new records.

Warning:  This isn’t documented or supported by Salesforce, and could change at any time.

First, you need the ID of the field in question.  If you’ve already created S-Controls to populate new fields, this probably isn’t new to you.  However, if you haven’t, the easiest way is to navigate to the field in question in Setup. (Create > Objects > Object Name > Field Name, for custom objects).  Then, take the ID from the URL of the custom field, for example:

http://ssl.salesforce.com/00N50000001xxxx

You’ll want to pass this as a URL parameter when creating your new object, with “CF” preceding the ID and “_lkid” appended.  You’ll also want to provide a value for the textbox, as the ID isn’t enough.  So you’ll want to pass something like this for a Contact:

?CF00N50000001xxxx_lkid=00N50000001yyyy&CF00N50000001xxxx=John%20Doe

Basically, it just comes down to knowing to append “_lkid” to the ID of the field you’re passing in with the Salesforce ID, as well as providing a value to display in the textbox on the creation screen.  Hopefully this helps you out!


Tags: , , , , ,
Posted in S-Controls, Salesforce.com | 3 Comments »

Free Salesforce.com S-Control to Dynamically Auto Refresh Dashboards

Written by ShamrockCRM on March 14, 2009 – 3:06 am

Ok, I have received many positive comments about this functionality that I posted about before regarding the auto refreshing of either a home page dashboard or an individual dashboard when a user simply visits the page.

I know that Salesforce offers the ability to schedule dashboards, but this is really to be used in the case of an organization having MANY dashboards and a Salesforce.com Administrator not wanting to schedule hundreds of dashboard refreshes.

Take a look at my original post explaining this Salesforce.com Dashboard Refreshing functionality

I am going to provide this useful code for you to use for free.  This is once again a very simple piece of code, but somewhat useful and unique.

1) Create an S-Control called whatever you’d like.  I called mine “Auto Refresh Dashboard.”

2) Paste in this code:

<code lang="html">&lt;html&gt;
&lt;head&gt;
&lt;script type="text/javascript"&gt;
function clickButton(){
var thebutton = parent.document.getElementsByName('refresh');
thebutton.item(0).click();
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body onload="clickButton()"&gt;
&lt;/body&gt;
&lt;/html&gt;</code>

3) Create a Home Page Component of type “HTML Area.”
4) Click “Show HTML”
5) Paste in the following code:

<code lang="html">&lt;iframe name="rss_iframe" src="/servlet/servlet.Integration?lid=XXXXXXXXXX&amp;ic=1" width="0%" height="0"&gt;&lt;/iframe&gt;</code>

6) Replace XXXXXXXXXX with the Salesforce.com record ID of the S-Control that you created above.
7) Add this home page component to your home page layout.

Now, the home page dashboard will always automatically refresh when Users visit their home page, preventing confusion by keeping data up to date!

Have fun!


Tags: , , , , , , ,
Posted in dashboards, S-Controls, Salesforce.com | 13 Comments »

Free Salesforce.com Advanced Search Code

Written by ShamrockCRM on March 4, 2009 – 9:41 pm

Ok, I have decided to be kind.  Everyone saw the post about the Advanced Search tool for Salesforce.com already and loved it.  Everyone requested it and I am in a very giving mood.

This is such a great little tool.  You can’t miss out on this little bit of functionality.

This Salesforce.com code is incredibly simple and very easy to install.  This can be used on any edition of Salesforce, including Group, Professional, Enterprise and Unlimited.

1) All you need to do is create a Salesforce Home Page Component.

2) Make this component of type “HTML Area.”

3) Click the checkbox that says “Show HTML.”

4) Add this snippet of HTML into the box:

&lt;script language="JavaScript" type="text/javascript"&gt;
    function submitSearchForm(){
        var searchField = document.getElementById('advsearchfield');
        document.advsrch.action = '/search/SearchResults?searchType=2&amp;sen=0&amp;setLast=1&amp;str=' + searchField.value;
        return true;
    }
&lt;/script&gt;
&lt;form name="advsrch" method="post" onsubmit="return submitSearchForm();"&gt;&lt;input class="searchTextBox" id="advsearchfield" maxlength="80" size="18" name="sbstr"&gt; &lt;input class="btn" value=" Go! " type="submit"&gt;&lt;/form&gt;

5) Add this Home Page Component to your Home Page Layout.

6) Done

Wasn’t that easy?  This will now allow you to have one simple search box, remove the old complicated one and search through all custom fields.  (external identifiers are excellent!)

Let me know if you need help installing this!

tanner@shamrockcrm.com

***Updated 4/1/2009 – Thanks Mike for the Small Improvement to the Code!
***Updated 4/9/2010 – Glenn provided a nifty way to prevent the search box from stealing cursor focus here. He suggests to show an image of a search box and replacing the image on mouseover with the actual search box. You need to take the image from his link above and use the following code below:

&lt;form
  id="searchForm"
  action="/search/SearchResults?searchType=2&amp;sen=0&amp;setLast=1"
  method="post"
  name="advsrch"
  onmousemove="if(getElementById('textBoxImage')) {document.getElementById('textBoxDiv').innerHTML='&lt;input id=\'searchField\' maxlength=\'80\' name=\'sbstr\' size=\'18\' value=\'\' type=\'text\'&gt;&lt;input value=\' Go! \' class=\'btn\' type=\'submit\'&gt;'}"&gt;
  &lt;div id="textBoxDiv"&gt;
    &lt;img id="textBoxImage" src="/resource/1269872073000/TextBoxImage2"&gt;
  &lt;/div&gt;
&lt;/form&gt;

If you are having problems with the Javascript version, use the below plain HTML version

&lt;form action="/search/SearchResults?searchType=2&amp;sen=0&amp;setLast=1" method="post" name="advsrch"&gt;&lt;input class="searchTextBox" maxlength="80" name="sbstr" size="18" value="" type="text"&gt; &lt;input value=" Go! " class="btn" type="submit"&gt;&lt;/form&gt;

Tags: , , , , , , ,
Posted in Business Analysis, S-Controls, Salesforce.com | 42 Comments »

Modifying Salesforce.com Dates Using Javascript

Written by ShamrockCRM on January 27, 2009 – 9:57 pm

CAUTION:  Technical jargon!!! Non-Business Related!!! Only interesting for Salesforce Developers.  :)

I ran across this interesting little problem while creating an orchestration in Cast Iron. I was creating a custom function that would adjust dates forward and back by weeks at a time.

What I found was, my small piece of code worked flawlessly 75% of the time. The 25% of the time would return a calculated date, or error, of “NaN-NaN-NaN.” I could not figure out what was wrong. I tested the code in the browser and everything worked properly.

From further testing and analysis, I determined that the code only broke when the month was July, August, and September or the day was the 7th, 8th, or 9th. I thought that this was very odd.

The code was taking a standard Salesforce date string formatted like “YYYY-MM-DD”, parsing out the text for the year/month/day, and using the parseInt Javascript function to convert the year/month/day into numeric values. I then created a Date object in Javascript and then made the date modifications.

Well, it turns out that parseInt is a bit quirky. If you do parseInt(“06”), this will return the number 6. If you do parseInt(“09”), this will return 0. ZERO?!?! Yes, 0. This is because parseInt will expect the number to be in Octal format if there is a 0 in front. There is no 09 in Octal. This causes the code to return 0, instead of the expected 9. So, when I subtracted 1 from the month to put the month in proper Javascript Date format, my code was inserting -1 as the month, therefore creating an invalid date. This only happened for the 7th, 8th and 9th months.

To resolve this, it was very simple. All you need to do is add “, 10” after the number to parse into an Integer (declaring a Radix) and it will consider this number to be of Base 10, solving your issue.  So, the correct code would be parseInt(“09”, 10).

To learn more about Javascript date modification for Salesforce.com S-Controls, take a look at this W3 Schools link.


Tags: , , , , ,
Posted in Programming, S-Controls, Salesforce.com, Web Development | Comments Off on Modifying Salesforce.com Dates Using Javascript

Salesforce.com S-Control Training Tips

Written by ShamrockCRM on December 22, 2008 – 9:27 pm

Another simple, but effective Salesforce customization with an S-Control.

Records in Salesforce.com are generally very bland and provide no direction as to what a User needs to do or needs to do next in the system.  I created an S-Control that will display whatever kind of HTML text that you would like directly on ANY record in Salesforce.com.  This text can be static or it can be constantly changing.  For example, you can coach a Salesperson along for each Opportunity Stage based on your Organization’s sales process.

You can detect that a User has not added any Products yet to the Opportunity and you can show them a HUGE red sign saying “Hey, it’s time to add a Product.  This is how…”

These can be placed anywhere on the screen, on any time of object, can say anything and can be based on any criteria.

salesforce.com training

Also, Instruct Users about individual fields!  The options are endless.

salesforce.com consulting and training

Obviously, this functionality could really enhance the User experience.  Everything will be a little less confusing, User adoption would increase, Users could be notified of recent functionality changes, their business process can be facilitated based on different criteria.

Contact me if this would interest you.


Tags: , , , , , , , ,
Posted in Business Analysis, Salesforce.com, Training | 1 Comment »

Sidebar Javascript Manipulation of Edit Pages

Written by ShamrockCRM on December 20, 2008 – 9:18 pm

Every once and a while, I just come up with some new, fun way to manipulate Salesforce.com that I have never known was possible.

Previously, you could never put any code on the Edit page of a record for Salesforce.com.  Because of this, you could not tie events to certain actions on the edit page, you could not override fields or override lookup windows.  You were pretty much limited to editing only the Read page.  VisualForce will allow you to work with the Edit page, but it is very limiting once you implement it for the first time.

With this little project, I placed a Sidebar Component on the Home Page Component.  This uses an IFrame to link to an S-Control.  With this, I constantly detect what page the User is currently on.  If they are visiting an Opportunity page, I know this.  If they are editing an Account, the code know.  With this ability, I can use the code to play with the edit pages.

In this example, I wanted to override the lookup field to take me to another page when the lookup icon is clicked.  For my example, I just used Google, but you could use this to take you to a filtered lookup field, which Salesforce does not currently offer.  If you want to only show Contacts for a certain Account or something like that, this could do it.  It would look just the same as normal.  AMAZING!

Also in this example, I implanted a training note onto the page to give the User instructional advice about a certain field.  Also useful!

One more thing, I defaulted the lookup field with a certain value.  Can you default a lookup field in Salesforce normally?  Nope.  Possibly useful for aiding in searching.

Exciting and interesting ideas, right?

salesforce.com development

force.com developers

salesforce.com developers


Tags: , , ,
Posted in Programming, S-Controls, Salesforce.com, Web Development | 5 Comments »

Automatically Refreshing Dashboards

Written by ShamrockCRM on December 19, 2008 – 9:18 pm

If your Salesforce.com Users are like most Users, they are always calling you asking why their Dashboards are incorrect.  Well, it’s because they forgot to refresh the Dashboard or they do not even know how to refresh the Dashboard.

Well, I found a unique little way around this.  I created a small piece of Javascript that can either be placed on everyone’s home page OR on the individual dashboards themselves.  Every time the User visits the page, the code will basically CLICK THE REFRESH BUTTON FOR THEM!  Great, right?

It is the simple things that make me the most happy.  This little script keeps all visited Dashboards up to date all the time automatically.  Let me know if you are interested in this script at all.

salesforce.com dashboards

salesforce.com reports

UPDATE: 8/15/2011 – Tons of requests for this script.  http://www.shamrockcrm.com/salesforce/free-salesforcecom-s-control-to-dynamically-auto-refresh-dashboards/

 


Tags: , , ,
Posted in Programming, S-Controls, Salesforce.com, Web Development | 23 Comments »

New Salesforce.com Advanced Search Tool

Written by ShamrockCRM on October 16, 2008 – 7:45 pm

I have created a great new tool for Salesforce.com that makes searching a heck of a lot easier for the average User of Salesforce.

Typically, with the normal Salesforce.com search box, it will ONLY search through Standard fields.  It will NOT search through any of the custom fields that you have created in the system.  This is very frustrating for the User.

Let’s say a User wanted to search for records that contain an external ID to another system in a custom field OR for some characteristic of a record.  ex.  Say you sell Pizza.  You have a field on the Contact record called “Favorite Topping”, with the value of “Pepperoni”.  With the normal Salesforce.com search, if you searched for “Pepperoni”, you would find ZERO results.  See the below screenshot.

salesforce.com advanced search

As you can see, no results showed up for the User.

If you use my new Advanced Search box that I used to replace the old Search box, you can see that Pepperoni immediately returned a result for the User.

salesforce.com search customization

This saves many clicks and TONS of confusion for the average Salesforce user.

Simple, but wonderful!

Click HERE for the Free Salesforce.com Code for this Functionality


Tags: , , , , ,
Posted in Programming, S-Controls, Salesforce.com, Web Development | 5 Comments »