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
JeeedeeeJeeedeee 

SOSL in Apex and OR function is it supported?

Hi all,

From the docs in Salesforce I see we can use the OR logic in the SOSL query. I am trying to search for both postal code and a phone number. I would like to get back Accounts, and maybe in the future also accounts... 

I keep getting save/compile errors, tried many ways of querying, but no luck yet... Does anyone have tried this before in apex (custom controller)

[code]
String phoneNr = ApexPages.currentPage().getParameters().get(PARAMETER_KEY_PHONE_NR);
String postalCode = ApexPages.currentPage().getParameters().get(PARAMETER_KEY_POSTAL_CODE);
List<List<SObject>> searchList = [FIND {:phoneNr OR :postalCode} IN ALL FIELDS RETURNING Account (Id, Name)];  // this does not save

List<List<SObject>> searchList = [FIND '0612341234 'OR '1000AA' IN ALL FIELDS RETURNING Account (Id, Name)];  // hardcoding also did not save
[/code]

Thanks! JD
VikashVikash (Salesforce Developers) 
Hi,

Please follow the link regarding OR operator in APEX.

http://www85.homepage.villanova.edu/timothy.ay/MIS2040/Secure2/Apex-cheatsheet.pdf
https://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_expressions_operators_understanding.htm
http://www.salesforce.com/us/developer/docs/soql_sosl/index_Left.htm
http://www.salesforce.com/us/developer/docs/dbcom_soql_sosl/Content/sforce_api_calls_soql_select_comparisonoperators.htm
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_comparisonoperators.htm

Thanks
Vikash_SFDC