Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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?

share|improve this question
    
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
add comment

2 Answers

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

share|improve this answer
    
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
add comment

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

vf:

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

javascript:

var MIN_SEARCH_LENGTH = 10;

$(document).ready(function() {
  bindSearch();
});

function bindSearch() {
  $("input#search-box").keyup(searchForDuplicates);
}

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>');
      }
    });
  }
}

apex:

@RemoteAction
public static List<SObject> searchForDuplicates(String dupeName) {
  dupeName = '%' + dupeName + '%';
  return [SELECT Id, Name FROM SomeObject WHERE Name like :dupeName];
}
share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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