3

I have a simple query in an Apex trigger:

SELECT Id, Name FROM Account WHERE Name in :Names

where :Names is a set of strings

Set<String> Names = new Set<String>();

This query fails with System.QueryException: Non-selective query against large object type (more than 100000 rows) when the set contains '.' string.

Names.add( '.' );

Can anyone explain this behavior? Does the dot character have a special meaning in SOQL?

By the way, the account record with the weird name "." exists if this is important.

Update. There are more than 100000 accounts, most of them are unique. I can select the accounts using Developer Console:

enter image description here enter image description here

As you can see, 2 records are selected. The exception rises when I try to reproduce the query in a trigger. I've created the most simple trigger that causes the exception:

trigger testTrigg on Contact (after insert) {
    Account[] accounts = [select Id, Name from Account where Name in ('.') limit 100];
}

Then I tried to create a contact and got the exception: enter image description here

As I see, I get a different query plan depends on value of searching. '.' value is surprisingly equal to NULL. enter image description here

enter image description here

1

1 Answer 1

1

I have tried in Developer Console, and there is no issue with the dot character.

Code

 Set<String> Names = new Set<String>();
 Names.add( '.' );
 List<Account> accounts = [SELECT Id, Name FROM Account WHERE Name in :Names];
 System.debug('hola ' + accounts);

Result

enter image description here

Let me share my thoughts about your issue

  1. If you really have more than 100000 Account records with the name ".", there is a big issue in your design. Check if that is what you really want and remove / update those which name could be different.
  2. If you don't have such a big amount of Accounts with "." as name, but you are not sure what is going on, try to run your query in the developer console and debug it. If you still get this issue, add a limit in order to retrieve less records and don't hit the issue. Maybe there is information that you don't know.
 [SELECT Id, Name FROM Account WHERE Name in :Names LIMIT 100];
  1. If you have so many records with this name, but you only want to retrieve some of them, you can always add another filter. Actually Salefsorce advice is to filter by a indexed field, for instance ExternalIds one. And if your field is requires to be indexed, you can make a request. However that is not your issue as you are filtering by Name Standard field that is already indexed.
3
  • Agustina, thanks for the answer. I have to add details.
    – maovrn
    Commented Jul 6, 2015 at 12:33
  • I've updated the question. Please see the details there.
    – maovrn
    Commented Jul 6, 2015 at 12:57
  • 1
    @maovrn I'm afraid I cannot help u too much ... actually I simulate your scenario and created 125014 accounts where 2 of them had '.' as name. Running count query and Select Id one I get same results as you. I also create the trigger you pasted above and create a contact with it without any issue. My last try advice is to check Name field on Account. It should have index checkbox ticked by default, but just in case. If not, this is a platform issue, because this field should be true to help you to deal with this kind of issues. If not ... post it in forums as well, maybe you're luckier there Commented Jul 7, 2015 at 14:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .