Retrieve API names of All object in Salesforce ORG using SOQL

  • How to write SOQL query to retrieve all the object Name and API names of Sobject in Salesforce

    Why do you need to have this by soql ? Have you already looked into schema describe ?

    Maybe because SOQL queries can be executed in the Developer Console, while APEX seems to require a sandbox to be set up, not to mention that you are stuck building a page and a class to get something so much more readily available via SOQL query. That's why I landed on this gold mine page, anyway.

  • You cannot do it with SOQL.

    You need describe call

    for ( Schema.SObjectType o : Schema.getGlobalDescribe().values() )
        Schema.DescribeSObjectResult objResult = o.getDescribe();
        system.debug( 'Sobject: ' + objResult );
        system.debug( 'Sobject API Name: ' + objResult.getName() );
        system.debug( 'Sobject Label Name: ' + objResult.getLabel() );   

    Run this code in Execute anonymous and check debug. You will get all the sobject name(API Name), label and other properties.

    Is there a way to determine which are custom objects vs standard objects? thanks

    @AndyHitchings you can check if the api name ends with __c or not to identify the custom and standard objects.

  • Here's a method I've found. It's more explicit than using the permissions object.


    SELECT  QualifiedApiName FROM FieldDefinition WHERE EntityDefinition.QualifiedApiName = 'Account' 


    SELECT  QualifiedApiName FROM EntityDefinition order by QualifiedApiName 

    I was searching for this for a very long time. Thank you so much it helped me to solve my issue.

    this approach appears to be limited to 200 results as EntityDefinition thows a EXCEEDED_ID_LIMIT error if run without adding LIMIT 200

    @Omkar More offered a solution to this. Scroll down.

  • String sObjectName = 'Project__c';
    System.debug('=========  '+ sObjectName);
    List<Schema.SObjectField> sss=new list<Schema.SObjectField>();
    if(sObjectName != null && sObjectName != '' )
    Schema.SObjectType gd = Schema.getGlobalDescribe().get(sObjectName); 
    Schema.DescribeSobjectResult a11=gd.getDescribe();
    Map<String, Schema.SObjectField> M = a11.fields.getMap();        
    for(Schema.SObjectField s1:m.values()){                            
        Schema.DescribeFieldResult f = M.get(s1.getDescribe().getName()).getDescribe();

    Thanks !!!

    Thanks for providing an answer. You might want to add some information to the question asker describing how this solves his/her problem?

  • I haven't compared the list to the describe list but you can find a list of presumably all SObjects within the ObjectPermissions table listed under the SobjectType field. This field is weird though and doesn't allow some filtering (no LIKE operator for example). There is also a possibility the list is generated only from SObjects that are not public read/write, but I haven't checked to see if that is the case.

    The proper way is definitely the describe, but this table might provide some insight as well in a quick query. I wouldn't use this route in production code though because of those uncertainties.

    SELECT SobjectType FROM ObjectPermissions

    Though Describe may be the officially sanctioned way to get the information, the SOQL way suggested by @oleg is a lot less work.

  • The Best Ways to retrieve list of all Objects using Apex, you can use Schema.getGlobalDescribe() method.

    Its simple use below code:

    for( Schema.SObjectType o: Schema.getGlobalDescribe().values())

    For more details check : The Best Ways to Retrieve Names of All Objects Using Apex

  • To get list of All Objects run below query from workbench:

    SELECT QualifiedApiName FROM EntityDefinition ORDER BY QualifiedApiName LIMIT 200 OFFSET 200

    Please know that there is a limit of max 200 records will be returned in list per retrieval. Hence add 'LIMIT 200' to restrict the result for first 200 records. Otherwise you will get below error

    "EXCEEDED_ID_LIMIT: EntityDefinition does not support queryMore(), use LIMIT to restrict the results to a single batch"

    If you need to get next results from record no 201 , 202, ... add 'OFFSET 200' to your query. this will show records from 201 to 400. Sililarly use 'OFFSET 400' for records from 401 to 600 and so on.

    The explanation of OFFSET opens the door to querying more than 200 objects. This is also hugely useful when you really need it.

    It should be noted that the SOQL OFFSET clause has a maximum offset value of 2000, limiting the total number of record you can retrieve in this fashion to 2200. You probably don't have 2200 SObjects in your org (but with enough managed packages, you could) - but for other uses of this solution, it is important to keep in mind.

  • for ( Schema.SObjectType obj : Schema.getGlobalDescribe().values() )
        Schema.DescribeSObjectResult objResult = obj.getDescribe();
        system.debug( 'Sobject: ' + objResult );
        system.debug( 'Sobject API Name: ' + objResult.getName() );
        system.debug( 'Sobject Label Name: ' + objResult.getLabel() );   

    How does this provide more information than the answers already given ?

  • Using the list of fields names at FieldDefinition Fields and the basic query given by @oleg, I got exactly what nobody seems to have figured out how to get, easily, from a developer console window. In my case, I needed a list of all the fields on our Lead object, along with their key attributes (Type, Length, Precision, Label, etc.).

    My SOQL query is as follows.

    SELECT QualifiedApiName, Label, DeveloperName, Description, DataType, ExtraTypeInfo,  Length, Precision, Scale FROM FieldDefinition WHERE EntityDefinition.QualifiedApiName = 'Lead'

    Getting the data from the console is a snap with the ColumnCopy extension for Chrome, about which you can learn more at It copies everything except the label row in one swipe. That’s easy enough to hand copy. I am thrilled over the moon!

  • With the following SOQL, you can get Customizable object without using limit and offset

    SELECT NamespacePrefix,  IsCustomizable, QualifiedApiName FROM EntityDefinition where IsCustomizable = true  order by QualifiedApiName 

    For more field can be used in where clause to avoid EXCEEDED_ID_LIMIT, you can refer to EntityDefinition Fields

License under CC-BY-SA with attribution

Content dated before 7/24/2021 11:53 AM