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
Alden GordonAlden Gordon 

SOQL queries from objects with multi-word names

I am attempting to execute a simple SOQL query on objects with two-word names, and it is proving surprisingly difficult. 

The query below works fine:
"select name from user limit 10"

I want to execute something similar on an object called "User Emails" - I know that is the name as it was pulled from the schema builder. However, any simple query on this table fails, no matter what format of the two-word name I try.

For example: 
"select date from user_emails limit 10" 
This fails with the error "Object type 'user_emails' is not supported". This is true of any format of the object name I have tried (useremails, UserEmails, user-emails, etc).

What is the correct way to query these objects? 


 
Best Answer chosen by Alden Gordon
Anurag VermaAnurag Verma
Hi Alden,

You will have to use API name in SOQL to get this work. To get API name for a custom object go to the setup->Build->Create->Objects. Click on the object "User Emails" from the list. Get the "API Name" from there and use that in your SOQL.

All Answers

Sridhar NarayansaSridhar Narayansa
Is User_emails a custom object? If Yes, use User_emails__C in the query. That is the API name of the object.

So your query will look like this. Notice __c in the for the field name and the object name. these are API names of the object and the field that needs to be used in the query.

select date__C from user_emails__c limit 10



If you are trying to get the email Id from the user object you will need to use the below query.

select Email from user limit 10

Good Luck!!

 
Anurag VermaAnurag Verma
Hi Alden,

You will have to use API name in SOQL to get this work. To get API name for a custom object go to the setup->Build->Create->Objects. Click on the object "User Emails" from the list. Get the "API Name" from there and use that in your SOQL.
This was selected as the best answer
Anilkumar KotaAnilkumar Kota

Hello Alden ,

Object name is different and api name is different while using Apex code we have to use API names. To find the api for any object or field goto the object detail page and pick the API name .Setup->Build->Create->Objects->API Name for Fields Setup->Build->Create->Objects->Fields->API Name.

In your case try with try select date from user_emails__c limit 10.