11

I'm having a problem consistently querying an object by an external id. When I do a SOQL query that has a queryplan that uses an index on the externalID, the record can not always be found. It is as though the index is corrupt, but I have no way to force a rebuild.

My minimum example:

I have a field named PID on the standard Contact object. PID is defined as autonumber (format p{00000}) and flagged as external ID.

For brevity, assume I have exactly two contact records with salesforce ids of 'record1' and 'record2' (I'm not going to try to type the real ones). The name fields of these two records contain 'name1' and name2' respectively.

Through the salesforce.com UI, I can search the names and find

Name: name1 PID: P00000 

and

Name: name2 PID: P00001 

In the force.com developer console,

query: select id, pid__c, name where name='name1' result: record1,'P00000','name1' query: select id, pid__c, name where id='record1' result: record1,'P00000','name1' query: select id,pid__c,name where pid__c >= 'p0000' result: record1,'P00000','name1' record2,'P00001','name2' query: select id, pid__c, name where pid__c = 'P00001' result: record1,'P00001','name2' 

****** BUT *******

query: select id,pid__c,name where pid__c='P00000' result: <no rows> 

There are actually about 8000 rows in this table with a bunch of other fields and externalIDs, but no duplicate PIDs since that's an autonumber field.

I haven't been able to detect a pattern as to which records can and cannot be located by PID. Some, like P00001 in this example, can be found and some, like P00000, can not. If a record can be found by PID once, it can always be found. If it can not be found by PID on the first attempt, it will never be findable.

Ideas, anyone?

Thanks -Jim

7
  • There aren't any odd character issues going on with the ID by chance? It could be as simple as a O rather than a 0 in the id. Or it could be a more exotic encoding issue with characters that look correct but are on another code page. If you copy and paste the external id value from the actual record to the SOQL query does it work? Commented Dec 9, 2014 at 22:15
  • Oh, it's an autonumber field, so it shouldn't contain any character encoding oddities. How about if you attempt an upsert via the API and use the problem PID__c as the externalIdFieldName. It should become an update as the matching record is found (which I assume will use the index). Commented Dec 9, 2014 at 22:23
  • Last idea, compare the Execution Plan between the query that works and the one that doesn't. There might be a clue there. Commented Dec 9, 2014 at 22:25
  • Just curious if you drop the WHERE clause if it will show the records in question. If so, instead of using the equal operator what returns if you were to use the like operator? Commented Feb 5, 2015 at 18:16
  • 3
    Are there any sharing rules at play here? Are you sure that the user you have logged in as has right to access the Contact record with PID 'P00000' and not just the record with 'p00001'? Commented Apr 7, 2015 at 11:42

1 Answer 1

2

This is known issue.

Remove and Recreate the External Id and unique properties of the custom field should resolve the issue. If the field is a custom indexed field, reach out to support for rebuilding the index on the field.

http://help.salesforce.com/HTViewSolution?id=000193737&language=en_US

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.