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:
<script language="JavaScript" type="text/javascript">
function submitSearchForm(){
var searchField = document.getElementById('advsearchfield');
document.advsrch.action = '/search/SearchResults?searchType=2&sen=0&setLast=1&str=' + searchField.value;
return true;
}
</script>
<form name="advsrch" method="post" onsubmit="return submitSearchForm();"><input class="searchTextBox" id="advsearchfield" maxlength="80" size="18" name="sbstr"> <input class="btn" value=" Go! " type="submit"></form>
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:
<form
id="searchForm"
action="/search/SearchResults?searchType=2&sen=0&setLast=1"
method="post"
name="advsrch"
onmousemove="if(getElementById('textBoxImage')) {document.getElementById('textBoxDiv').innerHTML='<input id=\'searchField\' maxlength=\'80\' name=\'sbstr\' size=\'18\' value=\'\' type=\'text\'><input value=\' Go! \' class=\'btn\' type=\'submit\'>'}">
<div id="textBoxDiv">
<img id="textBoxImage" src="/resource/1269872073000/TextBoxImage2">
</div>
</form>
If you are having problems with the Javascript version, use the below plain HTML version
<form action="/search/SearchResults?searchType=2&sen=0&setLast=1" method="post" name="advsrch"><input class="searchTextBox" maxlength="80" name="sbstr" size="18" value="" type="text"> <input value=" Go! " class="btn" type="submit"></form>
Related posts:
- New Salesforce.com Advanced Search Tool
- Free Salesforce.com S-Control to Dynamically Auto Refresh Dashboards
- Salesforce Changes for Delegated Authentication
- Modifying Salesforce.com Dates Using Javascript
- Salesforce.com JavaScript to Override Buttons
Posted in Business Analysis, S-Controls, Salesforce.com | 31 Comments »
31 Responses
to “Free Salesforce.com Advanced Search Code”
1 Trackback(s)
- Dec 30, 2009: » Advanced Search tips & tricks (The Enforcer.net, a force.com blog)

By Shannon on Mar 23, 2009 | Reply
I must say thank you for a nice little piece of code. I would buy you a beer.
By Tanner - Shamrock CRM on Mar 23, 2009 | Reply
I’ll take an AmberBock, please
By David- Kent Health Systems on Mar 24, 2009 | Reply
You rock … Thank you for your efforts and generosity
By Jenna on Mar 30, 2009 | Reply
Thank you so much for sharing this. Might not seem like a big deal, but this made me a big hit with my users. I went from being a system admin, to being the Wizard of Oz.
By Tanner - Shamrock CRM on Mar 30, 2009 | Reply
Jenna, you win the prize for the best comment EVER!
By Lisa on Mar 31, 2009 | Reply
You rock Tanner. Thanks for sharing.
By Mike on Apr 1, 2009 | Reply
Excellent! This is exactly what my org needed. I made a slight change so that the search keyword is displayed in the search box with the results.
By Valentino Rijhen on Apr 2, 2009 | Reply
Hi Tanner,
My javascript tag is being removed!
Any idea?
Do I have to configure some settings?
Thanks in advance!
Valentino Rijhen
By Jenna on Apr 7, 2009 | Reply
Tanner: And it’s no joke. Seriously. My users now call me Ozzie. Not sure how I feel about that yet, but it could be worse!
By Mark R on Apr 8, 2009 | Reply
Woot! We have a ton of integration and syncs into custom fields, and this is perfect. Our agents no longer need to pull up their RMA tool nor click into advanced search to pull up RMA or store records, etc. Thanks a bunch!
By Steve Fox on Apr 13, 2009 | Reply
Tanner – apprecaite the code. It looks like I have the same problem implementing as Velentino. The JavaScript code is being stripped from the HTML Component. Any suggestions?
By Ben on Apr 30, 2009 | Reply
This is the same as advanced search in salesforce. there’s nothing new here aside from the fact that it’s accessible via the ‘Home’ page. Am I correct?
Thanks
By Jeff Davidson on May 20, 2009 | Reply
Tanner – We have implemented this, and many of our users really like it, but….
When we are using it with the Call Center Connector, it forces the cursor into the Advanced Search box whenever the page or frame refreshes. This can can result in the page scrolling upward when you don’t want it to.
Is there a way to edit the code so it doesn’t force the cursor into the box?
Thanks!
By Harm Korten on Jun 5, 2009 | Reply
Another way of doing the same, without adding new components is this.
Edit the messages and alerts homepage component, add the following 3 lines of code (anywhere in the content of messages and alerts):
document.getElementById(’searchType’).value = ‘2′;
This will actually have the default searchbox, do an advanced search!
By Harm Korten on Jun 5, 2009 | Reply
Seems I cannot post tags, they got removed from my post….
By Ryan on Jul 3, 2009 | Reply
Harm,
Is there any other way i can get that piece of code. It would be really useful
Thanks
By Glenn Weinstein on Nov 24, 2009 | Reply
I love the “Advanced Search” component, but also have the same frustration (the cursor deafults into the textbox, causing some jarring scrolling if you’ve already started to page down while the page is loading). Any solutions?
By Eric Taylor on Dec 24, 2009 | Reply
How do we replace the standard Search box on all pages (not just the Home Page)?
Thank you.
By Kristin on Dec 31, 2009 | Reply
This is great, thank you for sharing!
By TJ on Jan 22, 2010 | Reply
I too would like to know how to add this search component to all objects, instead of the homepage only.
By ShamrockCRM on Jan 22, 2010 | Reply
Setup->Customize->User Interface->Show Custom Sidebar Components on All Pages.
By TJ on Jan 22, 2010 | Reply
Awesome. Thank you!
By Marcos. on Feb 3, 2010 | Reply
Thank you very much! I think this solution is nothing but espectacular!
It works with excelence… and it’s something many people asked for. In Spain we use the CIF (Fiscal Identification Code) for almost all searches… that’s a custom field in salesforce. This search feature rocks!
Thank you very much!
By Glenn Weinstein on Apr 3, 2010 | Reply
I’ve answered my own question here from 24 Nov 09. A colleague and I stumbled upon what we think is a pretty clever technique to avoid having the Advanced Search component always steal focus.
I’ve posted instructions & code for our technique on the Appirio Tech Blog:
http://techblog.appirio.com/2010/03/advanced-search-as-home-page-component.html
Please try & enjoy!
Glenn
By Charlotte on Apr 9, 2010 | Reply
This doesn’t work – the homepage just shows the text of the html code. What am I doing wrong?
By ShamrockCRM on Apr 9, 2010 | Reply
Hi Charlotte. Try copying the code into notepad first. Then, create the homepage component and paste the text into it while in HTML mode.
By Charlotte on Apr 9, 2010 | Reply
Never mind, I figured it out. I had to check the ’show html’ box before I pasted in the code.
By Malinda on Apr 28, 2010 | Reply
Hi Tanner – this is a great tool. Thank you!
I do have a few questions. Is there a way to incorporate the solution search in here as well? (Everything in one box) I still don’t understand why SFDC keeps this seperate from an advanced search.
Also when doing an advanced search and searching for a contacts last name and the account name, the search doesn’t return what is expected….you have to search for one or the other and then go to the related list to make you choice. Is there a way this can be done as well?
Thanks,
Malinda
By Sunil K on May 5, 2010 | Reply
Hi There,
Its Great. But, I was wondering, if we can modify the code just to display results for the object selected by the user rather than for all Objects
By Sunil K on Jul 9, 2010 | Reply
Its working great but howevee a small problem, the cursor always stays in the search box,but when a user modifies any of the look up fields until the user moves the cursor into the lookup field the cursor stays in the search box and if the user overlooks this and clicks enter (which will now do the search) all the data that he has input is lost causing some inconvenience to the users, is there anyways when a user tries to modify the lookup field, the cursor moves into that field rather than staying in the search box.