function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
EclipseTalkEclipseTalk 

SOQL usage - Looking for object by ID

Hello,

I'm trying to run a simple query to lookup if an object with a given id exist. If the id doesn't exist, the query returns an error "INVALID_QUERY_FILTER_OPERATOR", if the id exist I get the Contact object back.

 

Select Title,  AccountId From Contact where Id='123'

 

What is the correct query syntax to check if an SObject exist or not?

 

Thank you

Best Answer chosen by Admin (Salesforce Developers) 
SuperfellSuperfell
If you look at the actual error message as well as the error code, you'll see something like invalid Id field, meaning the Id value you provided is not in the format for Ids, if you supply a validly formated, but none-existant Id, the query will run correctly, and return no rows.

All Answers

SuperfellSuperfell
If you look at the actual error message as well as the error code, you'll see something like invalid Id field, meaning the Id value you provided is not in the format for Ids, if you supply a validly formated, but none-existant Id, the query will run correctly, and return no rows.
This was selected as the best answer
EclipseTalkEclipseTalk
Thanks. Yes, the id needs to have a lenght of 18 chars....