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
John SmithJohn Smith 

Help on SOSL Query, incorporating Where conditions.

I'm trying to build a SOSL query, but unable to figure out to incoporate "Where"Statement in the SOSL. 

My SOSL is as follows: 

 

string query = 'Find \'' + ContactSearch +'\' RETURNING contact(AccountId,Account.AccountNumber,Account.Name,' ;
query+= 'Id, Name, Phone, Email, CS_Support_Contact__c, RecordTypeId)';

 

I need to add the Where conditions,

Account.Status__c ="Active' and Inactive_Contact__c = false.

 

Please advise me in this issue.

Best Answer chosen by Admin (Salesforce Developers) 
Naidu PothiniNaidu Pothini
string query = 'Find \'' + ContactSearch +'\' IN Name Fields RETURNING contact(AccountId,Account.AccountNumber,Account.Name' ;
query+= 'Id, Name, Phone, Email, CS_Support_Contact__c, RecordTypeId WHERE Account.Status__c = \'Active\' AND Inactive_Contact__c = false AND AccountId <> null AND Account.RecordTypeId = \''+clientAccountId+'\')';   

 

String ClientAccountId = ClientAccountRt.Id;

 

Try this

All Answers

Naidu PothiniNaidu Pothini
string query = 'Find \'' + ContactSearch +'\' RETURNING contact(AccountId,Account.AccountNumber,Account.Name' ;
query+= 'Id, Name, Phone, Email, CS_Support_Contact__c, RecordTypeId WHERE Account.Status__c = \'Active\' and Inactive_Contact__c = false )';

 Try this.

 

I thik you still need to have IN condition in the Query. might be something like this

 

string query = 'Find \'' + ContactSearch +'\' IN Name Fields RETURNING contact(AccountId,Account.AccountNumber,Account.Name' ;
query+= 'Id, Name, Phone, Email, CS_Support_Contact__c, RecordTypeId WHERE Account.Status__c = \'Active\' and Inactive_Contact__c = false )';

 

John SmithJohn Smith

Thats worked, Thanks. I was trying to add two more conditions:

AccountId != null and Account.RecordTypeId = :clientAccountRT.Id

 

Its throwing up error, I think i missed some syntax. Can you please guide me.

Naidu PothiniNaidu Pothini
string query = 'Find \'' + ContactSearch +'\' IN Name Fields RETURNING contact(AccountId,Account.AccountNumber,Account.Name' ;
query+= 'Id, Name, Phone, Email, CS_Support_Contact__c, RecordTypeId WHERE Account.Status__c = \'Active\' AND Inactive_Contact__c = false AND AccountId <> null AND Account.RecordTypeId = \''+clientAccountId+'\')';   

 

String ClientAccountId = ClientAccountRt.Id;

 

Try this

This was selected as the best answer
John SmithJohn Smith

Thanks Naidu, It worked really well.

John SmithJohn Smith

Can we search multiple fields like Name and Phone Numbers

for example " IN Name Or Phone Fields"