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
GudachariGudachari 

Functionality Of SOQL And SOSL

Hi my name is Amar and i am very new to Salesforce and as well as SOQL and SOSL languages.

 

I have a doubt regarding the inner functionality of SOSL. Here is the point i created an Account, i gave a Account Name like "Sonia and" with out double quotes and also i gave Account Number like "and" in the same record. 

 

I opend Apex Explorer in that i opened SOSL tab and i am trying to search a record "Sonia and and and" here Sonia and is Account name. "and" this one is a operator(Marked as red in a search string). and the last "and" is Account Number. So when i click Send Request in SOSL tab it gave result.

 

Here my problem is how the salesforce will treat and operator. Here i have three "and" words. In these three how the salesforce detect which one is operator and which one is normal word...?

 

Can anybody gave a solution for this one. If any link is there please provide those links..

 

Thanx In Advance..

 

Thanks & Regards

Amar

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

Salesforce won't see any of those ands as an operator, because they are enclosed in double quotes, which means an exact phrase match.  To search for the word and, you would surround that in double quotes to ensure that it is not interpreted as an operator

 

If you wanted to search for records containing the phrase 'Sonia and' and the phrase 'and', you would use:

 

find ' "Sonia and" and "and" '...

 

There's full detail on the SOSL find query in the Web Services API Guide at:

 

http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_sosl_find.htm

 

and in the Apex Developer's Guide in:

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_SOQL.htm

 

 

All Answers

bob_buzzardbob_buzzard

Salesforce won't see any of those ands as an operator, because they are enclosed in double quotes, which means an exact phrase match.  To search for the word and, you would surround that in double quotes to ensure that it is not interpreted as an operator

 

If you wanted to search for records containing the phrase 'Sonia and' and the phrase 'and', you would use:

 

find ' "Sonia and" and "and" '...

 

There's full detail on the SOSL find query in the Web Services API Guide at:

 

http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_sosl_find.htm

 

and in the Apex Developer's Guide in:

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_SOQL.htm

 

 

This was selected as the best answer
GudachariGudachari

Hi Bob :smileyhappy:

 

Thanx For your reply. But here i have some doubts.. You said to search for word and surrounded that in double quotes but even though i did not surrounded in double quotes i got results. I gave like this in search box sonia and and and My problem is in this search string how sfdc will differentiate operators (and, or etc..). It will consider first one is the operator or second one or third one...?

 

But here the actual operator is the second one(and). But how to know the second one is the operator to sfdc. So please give me suggesstion to solve my problem. You said if you want to search sonia and, surrounded it into double quotes but even though i did not surrounded like that i got results. So please clarify my doubts.. Thanx in Advance..

bob_buzzardbob_buzzard

I'd expect there to be results based on the word "Sonia".  According to the docs, the ands should all be treated as operators, but as there isn't another search string they may well cancel each other out.

 

GudachariGudachari

Hi Bob

 

I think i also expected the same thing but here is a problem. I created 3 records in Account object.

1. First record contains Account Name -- Sonia and Account Number -- and

2. Second record contains Account Name -- Sonia

3. Third reconrd contains Account Name -- and

 

These three records were created in my account. I am trying to search for a word like this Sonia and and and. As our expectation the sfdc will gave the two records that are contains Sonia. But it gave three records when i search for this word. So here i think our expectation was wrong. So here i stuck for the solution.

 

Why i am pressing this question was i am writing one parser. That parser will do seperate key words of sfdc and normal words. So how can i diferentiate normal words and sfdc keywords. For example i am the user i am searching for a token like above. I know the middle and is the key word, why because i am the one search for that string.  So how sfdc will know this is the keyword and this one is the normal word. It will treat all and's are keywords or some other way... 

 

So please provide a solution..

Thanx In Advance..

bob_buzzardbob_buzzard

It may well be that if Salesforce encounters a repeated and it assumes the first is an operator.  I'm afraid this isn't documented and its not something I've come across before.  You'll need to talk to Salesforce support to get a definitive answer on this one.

GudachariGudachari

Thanx bob

 

And one more help how can i talk to salesforce support team can you please tell me if any links please send me..

 

Thanx In Advance.

bob_buzzardbob_buzzard

You'd need to raise a case through your Salesforce edition.  If you click on the Help and Training link you can raise a case that way.  

GudachariGudachari

Hi Bob

 

You Said raise a case through your Salesforce edition. For that you said click Help and Training link you can raise the case i search for that but i can't Where can i find this Help And Training Link could you please provide elaboratly. I am very new to salsforce. Thats why i am asking. So could you please provide the link.

 

Thanx In Advance.

bob_buzzardbob_buzzard

Once you have logged into your salesforce org through the UI, you'll see a 'Help and Training' link near the top right of the page.

GudachariGudachari

Thanx Bob,

 

I posted my question and they accept my case waiting for reply.

 

Bob i have another question

 

Come to SOQL i insert a record like "DirecTV Group" as one record in account object and i inserted another record which is in encrypted form like "**FqbmcKDdollb85! **Hglmnblqbjj95!". But here is the problem...

1. When i search for the record DirecTV Group in search bar it will gave the record in the same way the encrypted value also. When i search with in the Double Quotes ("DirecTV Group") it will show this record. But i search a record of encrypted one surrounded with in the double quotes like ("**FqbmcKDdollb85! **Hglmnblqbjj95!") its not returning a value. So why it's not return any value when i search the encrypted word with in the double quotes.

This is also one of the major issue in my project. I stuck with this please provide a solution for this.

bob_buzzardbob_buzzard

Your encrypted values have asterisks at the beginning, which means a wildcard to salesforce.  However, I don't think you can have wildcards at the beginning of a search, from memory you have to have at least two characters before the wildcard.