function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Daniel WrayDaniel Wray 

query a contact

Hi,
 
I have tried various forms of this code ( shown below), but with no sucess,  sometimes it is not complaining but also not retrieving any records.  note: dest is a mobile number
 
Many Thanks
 
Anita
 
// not working but not complaining!!! First attempt
 
sforceClient.Query("Select Id, FirstName, LastName From Contact Where Mobile = ' " + dest + " ' ", bindToForm);
 
// Or second go not working but not complaining!!!
 
sforceClient.Query("Select Id, FirstName, LastName From Contact Where Mobile = '{!Contact_MobilePhone}' ", bindToForm);
 
function bindToForm(queryResult)
{
var obj;
alert("im here in the bindToForm method!!");
if (queryResult.size == 1)
{
var firstName = "";
var lastName = "";
obj = queryResult.records[0];
firstName = queryResult.records[0].get("FirstName");
lastName = queryResult.records[0].get("LastName");
alert(firstName);
alert(lastName);
}
 
// code complaining object doesn't support this query
 
var contact = new sforceClient.Query("FirstName_c, LastName_c From Contact_c Where Mobile = '{!Contact_MobilePhone}' ");
if (queryResult.size == 1)
{
var firstName = "";
var lastName = "";
obj = queryResult.records[0];
if (contact.className == "QueryResult")
{
 firstName = contact.records[0].get("username__c");
 password = qr.records[0].get("password__c");
}
alert(firstname);
alert(lastName);
 
DevAngelDevAngel
If what you are writing is some kind of CTI functionality (screen pop on inbound call for instance) I highly recommend that you use the search command using SOSL.

Consider the following two statements

query("Select c.MobilePhone, c.Phone from Contact c Where Phone = '4159015100'")

search("FIND {4159015100} IN PHONE FIELDS RETURNING Contact (FirstName, Id, LastName)")

The first returns no records, the second returns all contacts that have that number in ANY phone field.  The query uses the formatted version of the phone field where the search just uses the numbers.  This makes search much more useful for determining the owner of a phone number since you can just strip out the non-numeric characters in the phone number string and feed that to the search call.

Cheers

Message Edited by DevAngel on 07-11-2006 10:29 AM

Daniel WrayDaniel Wray
Hi,
 
Thank you very much for your help over the past few days.  I see your point over the diff between the two queries  so I tried:
 
var test = sforceClient.search("FIND {447787502823} IN ALL FIELDS RETURNING Contact (FirstName, Id, LastName)")
         FirstName = "";
        //password = "";
        if (test.className == "QueryResult")
        {
                FirstName = test.records[0].get("FirstName__c");
        }
       alert(FirstName);
  
 
Also tried this on IN PHONE FIELDS BUT neither query returned anything or complained about the code????
 
HELP??? thanks
DevAngelDevAngel
Please examine the documentation for the search call.  It does not return a query result, it actually returns a searchResult object.
greystokegreystoke
Hello Dave,

I encountered a problem when trying to lookup a Contact with a phone number delivered by some CTI monitor point with either a search or a query.
Let`s say the contact phonenumber is entered in a canonical format in the main phone field of a contact, "+49(40)334-2711".
Often, the international code is omitted in the signaling from the PBX when an incoming call arrives.

All I have in my application in such a case is the number "403342711".

Neither a SOSL Seach:
FIND {403342711} IN PHONE FIELDS RETURNING Contact(Id, LastName)

or a SOQL Query:
SELECT Id, LastName FROM contact WHERE phone LIKE '%403342711'

will return the corresponding contact as a result.

The problem with the search statement is, that it is not allowed to use wildcards at the beginning of the search term. I would have to guess a prefix for the signaled phone number, something which I would like to avoid.
On the other hand, as you mentioned above, in the SEARCH only the numbers of the phone fields are compared.
That leads to the problem with the above QUERY which compares the formatted strings and will not find the contact because of the canonical number format of the entered phone number.

Do you have an idea how I can circumvent any of these two problems?

Thanks for your help

Christian
DevAngelDevAngel
I can't think of anything that doesn't smack of hack.  Are you sure you can't use wild cards in the search call?
greystokegreystoke
Hi Dave,

thanks for the quick reply!

You can use wildcards  (* or ?) in a search call, but unfortunately not at the beginning of the searchString. At least this is stated in the AppExchange Web Service Developer Guide for 7.0. I tried it anyway and it does not lead to an error, but the wildcard character is ignored.
Because of that, we have to know the accurate start of the phone number for the use in a search call.
But what we have is the accurate ending of the phonenumber, so to say...
:-)

Christian

The_FoxThe_Fox
Hello,

I know that may seems a bit weird but If you do soemthing like

For Counter=0 to 9

Search(Phone, Counter*EndofPhoneNumber)

maybe a bit slower but it could work, regards