When you want to find records for more than one Object based on search string that you specify is called SOSL.
We are passing the entire SOSL expression in “StringsearchExpr”
parameter of the search() call.
SOSL does not search the following object and fields
- Any elements such as picklist that are defined as not searchable()
- Number,date or checkbox fields. (Use SOQL to search this fields)
- Textarea fields, unless you use the ALL FIELDS in search group.
- Attachment records associated with Account, contact or opportunity.
Example Query
In Apex:
FIND ‘keyword*’ IN ALL FIELDS RETURNING Account (Id, Name), Contact,
Opportunity, Lead
In Force.com API
FIND {keyword*} IN ALL FIELDS RETURNING Account (Id, Name), Contact, Opportunity,
Lead
Find Keyword
Find Keyword
- You can search a single word or a phrase.
- You can use “ ”,AND,OR,AND NOT,().
- Reserved Character:
? & | ! { } [ ] ( ) ^ ~ * : \ " ' + -
If we are using the above characters, then we should use backslash \ character
(escape sequence).IN Search group:
This is optional clause, which allows you to define the type
of fields to search.
ALL FIELDS
EMAIL FIELDS
NAME FIELDS
PHONE FIELDS
SIDEBAR FIELDS
Returning:
Syntax:
Returning ObjectTypeName [(Fieldlist [where
ConditionExpression] [order BY Clause] [LIMIT n])][ ,ObjectTypeName[(FieldList)
[where ConditionExpression] [Order BY clause] [Limit n])] ]
Object Type Name
|
Object to return.
|
Field List
|
Optional One or more field from the object
|
Where Condition
|
Optional, Specify the filter for the particular object
|
Order By Clause
|
Optional, Arrange the given values in asc and desc for the specified
object.
|
Limit n
|
Optional, Number of rows the query should return for the specified
object.
|
With Division :
The division should be enabled for the organization, in
order to use this syntax. It will act similar to where condition. But if we use
division keyword, below are the advantages.
- It pre-filters all records based on division before applying other filters.
- You can specify the division’s name in the filter, rather than its ID( as is required if you filter on division in the WHERE clause)
To Label:
Syntax:
toLabel(Object.field)
FIND ‘string*’ RETURNING Account(Name, toLabel(Recordtype.Name))
This query returns Account records with the record type name translated into the language for the user who issued the query.
We cannot filter on the translated name value of the record type. Always filter on the master values or the ID of the object for record types.
No comments:
Post a Comment