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
Mohana Priya SwamiappanMohana Priya Swamiappan 

unknown error parsing in nested soql queries

I have 2 objects viz., User, Contact. 
Both the objects have a custom field called org1userId which is an Id in an ecternal system. I also have a custom field(UserId) in contact to store the Id of the user record. 
I want to fetch Id from user and userID  from contact which matches the org1userId. 
My sql is as follows 
select u.Id , c.userId__c from user u, contact c where u.org1userID__c='xxxxxxxxxxxx' and c.org1userID__c='xxxxxxxxxxxx'
I am unable to convert this query into a soql.
I am an amateur in salesforce. Any help is much apprecitaed. TIA
 
v varaprasadv varaprasad
Hi Mohana,

UserId is a custom lookup field or formula field. Please let me know so that can i can help you according;y.

Please try once below query.

 
select Id,userId__c.id,userId__c from contact org1userID__c='xxxxxxxxxxxx' and userId__c.org1userID__c='xxxxxxxxxxxx'


Hope this helps you!
If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others.

Thanks
Varaprasad
@For Support: varaprasad4sfdc@gmail.com
Blog: http://salesforceprasad.blogspot.com/

Salesforce latest interview questions  :
https://www.youtube.com/channel/UCOcam_Hb4KjeBdYJlJWV_ZA?sub_confirmation=1

 
Mohana Priya SwamiappanMohana Priya Swamiappan
UserID is neither a formula or a lookup field. I populate this field through an api call
Raj VakatiRaj Vakati
try this 
select Id , userId__c,(Select Id from Contact) from user where userID__c='xxxxxxxxxxxx'

 
Mohana Priya SwamiappanMohana Priya Swamiappan
This is not working as our query is trying to select userID__c from user , which doesnt exist in user . We need to pick the Id of the user which matches userid__c in contact and the field org1userid field must be the same in both the  user and contact.
Raj VakatiRaj Vakati
Try this 
select Id from user where org1userID__c='xxxxxxxxxxxx' AND Contact.org1userID__c='xxxxxxxxxxxx'


 
Mohana Priya SwamiappanMohana Priya Swamiappan
Sorry Raj the query didnt work . it is giving an empty result.