You need to sign in to do that
Don't have an account?
Kapil_Khandelwal
Error in SOSL "find" query
When I run following query in Query Editor of Developer Console, I get the expected output.
Kindly help me regarding the same.
Thanks in advance.
FIND {old} IN ALL FIELDS RETURNING Shala, Id, Contact(FirstName)But when I run same query in my Apex code, I get an error.
List<List<SObject>> oldList = [FIND {old} IN ALL FIELDS RETURNING Shala, Id, Contact(FirstName)];
Kindly help me regarding the same.
Thanks in advance.
Try to create declare old as String variable and then pass it.
Refer below sample code.
Below is the sample code that has a input text box and a command button which will search for the entered string in three Object . i.e Accounts, Contacts, Opportunities and returned result will be shown in the page block tables.
Please mark it as solved if my reply was helpful. It will make it available for other as the proper solution.
Best Regards
Sandhya
Try this
List<List<SObject>> oldList = [FIND :('*' + searchText + '*') IN ALL FIELDS RETURNING Shala, Id, Contact(FirstName)];
Hope it helps,
Thanks
Sumitha P
In query editor we write the string to be matched as {stringToBeMatched} and in apex code, we use ( ' ) to specify the string to be matched.
So you can write your query as:
to avoid error.
For more information regarding how to write SOSL queries visit https://trailhead.salesforce.com/en/modules/apex_database/units/apex_database_sosl
Mark this as best answer if it helps.
Shubham Nandwana.
AppPerfect Corp.
salesforce@appperfect.com
408-252-4100
http://www.appperfect.com/services/salesforce/
Salesforce Development & Operations Experts
We have to use- ' at the start of string and end in Apex code
Try this code
List<List<SObject>> searchList = [FIND 'old' IN ALL FIELDS
RETURNING Account(Name), Contact(FirstName,LastName)];
system.debug('--->'+searchList);
proper syntax used for sosl :
FIND {SearchQuery}
[ IN SearchGroup ]
[ RETURNING FieldSpec [[ toLabel(fields)] [convertCurrency(***Amount***)] [FORMAT()]] ]
[ WITH DivisionFilter ]
[ WITH DATA CATEGORY DataCategorySpec ]
[ WITH SNIPPET[(target_length=n)] ]
[ WITH NETWORK NetworkIdSpec ]
[ WITH PricebookId ]
[ WITH METADATA ]
[ LIMIT n ]
[ UPDATE [TRACKING], [VIEWSTAT] ]
for more information go to below link:
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_sosl_syntax.htm
Mark as best answer if it helps you
Thank You