We have an internal defect tracker in Salesforce which should have much more of the charming features of Stackexchange.

One feature that I love the most is the live-search for duplicates while entering a new question.

Is there a way to implement such a search on hundreds of records in Salesforces? I have no experience SOSL but I guess this could be of great help for building this.

Has anyone build this or have seen tutorials on parts that I could need?

  • You may want to ask a more specific question; what you're describing is a pretty straightforward tie together of some ajax calls that read character input, a SOSL query or two, and a way of displaying the results to the user. You may want to check out the jQuery documentation on their autocomplete support, which you may or may not want to use - but it also contains some examples reading character input and proactively searching via AJAX. I've integrated it with Visualforce many times, it works well. – jkraybill Feb 5 '13 at 3:22

Andy Mahood has built something similar with Autocomplete for Salesforce, which you could draw inspiration from.

It's also natively available on the Idea object... sorta. search for duplicates

  • If Salesforce.com used this for Ideas there must be someone how knows how to build this. Andy Mahoods solution doesn't seem to perform well, so i don't want to dig into it. – Robert Sösemann Jan 28 '13 at 8:33

Here is a basic implementation. Write it using javascript & remoting and it will probably be adequately fast.


<input type="text" id="search-box" value="" />
<br />
<ul id="duplicate-results">



$(document).ready(function() {

function bindSearch() {

function searchForDuplicates() {
  var currentValue = $.trim($(this).val());

  if(currentValue && currentValue > MIN_SEARCH_LENGTH) {
    MyController.searchForDuplicates(currentValue, function(result, event) {
      var $addTo = $('ul#duplicate-results');
      for(var i = 0; i < result.length; i++) {
        $addTo.append('<li>' + result[i].name + '</li>');


public static List<SObject> searchForDuplicates(String dupeName) {
  dupeName = '%' + dupeName + '%';
  return [SELECT Id, Name FROM SomeObject WHERE Name like :dupeName];
  • I think the Remoting architecture looks great. But the use of SOQL LIKE will restrict us to use "short" text fields, right. No chance to search in long text fields. – Robert Sösemann Jan 28 '13 at 19:23
  • 1
    You could just alter my example to use a sosl search instead of a soql query. – Phil Rymek Jan 28 '13 at 19:30
  • BTW: The code like you posted it does not work. The way to call the remote action from Javascript ist different. – Robert Sösemann Feb 4 '13 at 20:28
  • could this hit query limits if the user is doing a lot of typing/deleting? – Phil B Jun 12 '14 at 17:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.