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
rtyanasrtyanas 

In an SOQL statement "where lookupField = 'string" invalid ID field:

In my Database.query() I am passing the string below for custom objects.  The field Version_of_Software is a lookup field into another object for validation.  When I run the query I get the error:

Version_of_Software__c From API_Document__c where Version_of_Software__c = 'Start ^ ERROR at Row:1:Column:77 invalid ID field: Start Time

Select Id, API_Name__c, Version_of_Software__c
 From API_Document__c
where Version_of_Software__c = 'Start Time'

How do I search this object on the lookup field?

RT

 

Best Answer chosen by Admin (Salesforce Developers) 
Vinit_KumarVinit_Kumar

I think you want look for name value in where filter,then the query should be 

 

Select Id, API_Name__c, Version_of_Software__c
 From API_Document__c
where Version_of_Software__r.name = 'Start Time'

All Answers

Vinit_KumarVinit_Kumar

I think you want look for name value in where filter,then the query should be 

 

Select Id, API_Name__c, Version_of_Software__c
 From API_Document__c
where Version_of_Software__r.name = 'Start Time'

This was selected as the best answer
rtyanasrtyanas

Thanks for response.  I am getting the same error in

 

Developer Console - Query Editor:

 

Select Id, API_Name__c, Version_of_Software__c
 From API_Document__c
where Version_of_Software__c = 'Start Time'

 

 

Version_of_Software__c From API_Document__c where Version_of_Software__c = 'Start ^ ERROR at Row:1:Column:77 invalid ID field: Start Time

Vinit_KumarVinit_Kumar

You are still using the same query,try the below one :

 

Select Id, API_Name__c, Version_of_Software__c
 From API_Document__c
where Version_of_Software__r.name = 'Start Time'

 

rtyanasrtyanas

Yes, that was it.  I am using the same name in the field as the look up object and thought I was searching based on lookup value.

 

If the lookup field was Ver and the lookup object was Version would this work?

 

Select Id, API_Name__c, Version_of_Software__c
 From API_Document__c
where Ver = 'Start Time'

 

Or do I still need to use the lookup object:

 

Select Id, API_Name__c, Version_of_Software__c
 From API_Document__c
where Version.name = 'Start Time'