Hot answers tagged

25 votes

Only variable references are allowed in dynamic SOQL/SOSL

If you use : in your query, Apex expects a variable. In case you are querying with the string, you should not use the :, but escape single quotes(\'). So your query should look like this: asset = ...
Novarg's user avatar
  • 5,266
13 votes
Accepted

Can we have a ORDER BY Clause in SOSL

I think you should update your query to FIND 'Cisco Systems*' IN ALL FIELDS RETURNING Account( ownerid,name,website WHERE (name LIKE '%Cisco Systems%' ) OR (Website_Domain__c LIKE '%cisco.com%'...
ipradhansk's user avatar
  • 2,317
11 votes
Accepted

Does SOSL allow the `-` dash character?

Not sure why that part of the documentation is not mentioning - and + characters, but they are reserved according to this documentation: Reserved Characters The following characters are ...
smukov's user avatar
  • 5,543
10 votes
Accepted

What is the default sort order for records in SOSL

For all intents and purposes, the default order is indeed the same for both SOSL and Global Search, as they use the same search indexes and algorithms. This places the API and Global Search on equal ...
sfdcfox's user avatar
  • 487k
10 votes
Accepted

SOSL not returning record in test

SOSL doesn't return results in test classes, so you have to use special methods to set the results. To ensure that test methods always behave in a predictable way, any Salesforce Object Search ...
Aidan's user avatar
  • 13.6k
8 votes

How to query child to parent

If you want get the parent object information then you need to use like this. SOQL Child to Parent for(Contact objContact: [SELECT Id, LastName, AccountId, Account.Name FROM Contact]) { system....
Ratan Paul's user avatar
  • 22.6k
8 votes
Accepted

Using SOSL with where clause

As per the Developer Guide on SOSL WHERE clause, it is used to filter the search results: By default, a SOSL query on an object retrieves all rows that are visible to the user. To limit the search, ...
dino ursic's user avatar
  • 2,323
8 votes

Question about setFixedSearchResults() Apex Tests with SOSL

The latest call to Test.setFixedSearchResults overwrites whatever happened before. The comment is only meant to state that you can simulate multiple SOSL searches in a single unit test. Of course, ...
sfdcfox's user avatar
  • 487k
8 votes
Accepted

System Permissions Assigned to Permission Set

There are many fields available on permissionset object. You can query those permission which you need. In general:- PermissionsPermissionName One field for each permission. If true, users assigned ...
sanket kumar's user avatar
  • 15.2k
7 votes
Accepted

Function to properly escape dynamic SOSL input

I just had to work on this problem too. I took a slightly different approach and let regular expressions do the bulk of the effort via the Matcher.replaceAll( string ) method instead of looping and ...
Doug Ayers's user avatar
  • 4,166
7 votes
Accepted

I wanna run my SOSL to search for a string obtained by function parameter

I'm pretty sure there's a duplicate out there somewhere, but the answer is you have to bind to the query: List<SObject[]> searchList = [FIND :param IN ALL FIELDS RETURNING Contact(FirstName, ...
sfdcfox's user avatar
  • 487k
7 votes

Only variable references are allowed in dynamic SOQL/SOSL

The dynamic SOQL documentation explains that simple bind variables (introduced with a :) can be used, that is a reference to a variable (but not a dotted expression or method call). So the pattern to ...
Keith C's user avatar
  • 136k
7 votes

Array notation for List<List<Sobject>>

The why is lost to time, I doubt there was a conscience decision. [] is a bit of an oddity in Apex. Apex doesn't have a notion of array so [] is only syntax sugar for list.get(i). When I rewrote the ...
spags's user avatar
  • 71
7 votes
Accepted

SOQL query to fetch records with reserved characters ('*', '/', '(', ')')

The * character is not a special character as far as SOQL is concerned. Here's a trivial proof for you: And here's the same in Apex: System.debug( Database.query( 'SELECT Name FROM ...
sfdcfox's user avatar
  • 487k
7 votes
Accepted

SOSL query the encrypted text field is possible but NOT in Apex test class?

In test classes, SOSL queries don't return anything by default. You have to define the results of the search yourself using Test.setFixedSearchResults. For example: @isTest public static void ...
fred's user avatar
  • 3,215
6 votes
Accepted

SOSL Search Results incomplete?

It's working as expected. Wildcards at the beginning of the word are not directly supported. From FIND {SearchQuery}, there's a specific note: Asterisks match zero or more characters at the middle ...
sfdcfox's user avatar
  • 487k
6 votes
Accepted

How to query for articles without a data category?

I know this is an old question, but I ran into the same problem today, and solved it like this: Select Id, ArticleNumber, Title from ArticleType__kav where Id not in (Select ParentId from ...
koma's user avatar
  • 96
6 votes
Accepted

SOSL does not find numeric fields

Correct. Per the Developer's Guide, SOSL is for "text-based search queries". On the FIND page, it also says in many ways that it is for words or phrases. If you have a number inside of a text field, ...
caleb.breckon's user avatar
6 votes

can we query SOSL using REST API?

Yes you can do SOSL query using REST Api. The api would be - /services/data/v37.0/search/?q=SOSL search string The SOSL search string needs to be URL encoded. Here is a link for more details - SOSL ...
Santanu Halder's user avatar
6 votes

Not getting a value in SOQL

Format your input variable with like operator and then use it in SOQL. Refer below code: MVImportBatch__c record = [select Id from MVImportBatch__c limit 1]; string cid = string.valueOf(String....
Rohit Mourya's user avatar
  • 3,851
6 votes
Accepted

SOQL Like Query?

Have you considered: Select Id, Name FROM Account WHERE Name LIKE '%Sales%Force%' or: String likeValue = '%Sales%Force%'; Account[] accounts = [Select Id, Name FROM Account WHERE Name LIKE :...
Keith C's user avatar
  • 136k
6 votes

How to get list of all sobject records modified today in the system?

Simpler way? well yes and no. We have Database.getUpdated method that returns Id of records updated in a particular time span. It takes sObject Type , start date and end date as arguments and returns ...
Pranay Jaiswal's user avatar
6 votes
Accepted

Apex SOSL-query doesn't work

SOSL indexing lags behind record creation, possibly by up to a few minutes. You may simply need to wait for the record to be indexed before it can be searched. You definitely cannot find a record that ...
sfdcfox's user avatar
  • 487k
6 votes
Accepted

How to return List of a list in Apex Rest Get Method Using SOSL

Don't mix responseBody and a return value. Use one or the other. It's a lot easier to use the return value, and offers more functionality for no extra effort, such as supporting XML and JSON input and ...
sfdcfox's user avatar
  • 487k
5 votes

SOQL query FeedItem by community

This is a known issue: https://success.salesforce.com/issues_view?id=a1p30000000T3J1AAK Until this is fixed, Workaround Remove the filter out of the SOQL query and filter in code. Leaving ...
glls's user avatar
  • 20.1k
5 votes
Accepted

SOSL syntax - Is first list element a single record?

When you do a SOSL search, it returns a List<List<SObject>>. If you're trying to get results for exactly one object type (Lead, for example), you might just want the one List<SObject>...
Adrian Larson's user avatar
  • 150k
5 votes
Accepted

What is difference between status and body column of ApexClass?

To answer your question, Status is of type Picklist while Body is a Long Text Area. You can find out all you need to know about the ApexClass object in the SOAP API Developer Guide. Filtering on Long ...
TSmith's user avatar
  • 4,992
5 votes

Bulkify SOSL query in loop

To bulkify the method, SOSL should be outside of for loop. Correct syntax for joining field is (refer documentation): FIND {"Joe Smith" OR "Joe Smythe"} IN Name Fields RETURNING ...
Santanu Boral's user avatar
5 votes
Accepted

expecting a right parentheses SOSL

There's a missing ' character here: OR Employee_Id__c like '%gar%) Must be replaced by: OR Employee_Id__c like '%gar%')
Martin Lezer's user avatar
  • 7,295
5 votes
Accepted

Test Method for @HttpPost RestResource is not returning expected results

Have a read of Adding SOSL Queries to Unit Tests: To ensure that test methods always behave in a predictable way, any Salesforce Object Search Language (SOSL) query that is added to an Apex test ...
Adrian Larson's user avatar
  • 150k

Only top scored, non community-wiki answers of a minimum length are eligible