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
Kevin OcieKevin Ocie 

Need to get salesforce object list

We are trying to pull a list of all the Salesforce Objects (tables names) from Salesforce. The name of the Object is already known. I want to see the entire list of Objects prior to that. Is this possible?
Best Answer chosen by Kevin Ocie
AbhishekAbhishek (Salesforce Developers) 
You can use Schema.getGlobalDescribe().Values() to get descriptions of each object, which are of type Schema.SObjectType. Then you can call the .getDescribe() method to get the object description, then call the .getName() method on the object description to get the object name:

for(Schema.SObjectType objectType : Schema.getGlobalDescribe().Values()){
    String name = objectType.getDescribe().getName();
    System.debug('Object name is==>' +name);
}

I hope you find the above information is helpful. If it does, please mark as Best Answer to help others too.

Thanks.

All Answers

AbhishekAbhishek (Salesforce Developers) 
You can use Schema.getGlobalDescribe().Values() to get descriptions of each object, which are of type Schema.SObjectType. Then you can call the .getDescribe() method to get the object description, then call the .getName() method on the object description to get the object name:

for(Schema.SObjectType objectType : Schema.getGlobalDescribe().Values()){
    String name = objectType.getDescribe().getName();
    System.debug('Object name is==>' +name);
}

I hope you find the above information is helpful. If it does, please mark as Best Answer to help others too.

Thanks.
This was selected as the best answer
Maharajan CMaharajan C
Hi Kevin,

Execute the below code from Workbench or developer console so you will get the CSV File with Object Names:
 
string excelHeader = 'ObjectName\n';
for(Schema.SObjectType objectType : Schema.getGlobalDescribe().Values()){
    String name = objectType.getDescribe().getName();
    System.debug('Object name is==>' +name);
	excelHeader += name +'\n';
}
Messaging.EmailFileAttachment csvAttc = new Messaging.EmailFileAttachment();
blob csvBlob = Blob.valueOf(excelHeader);
string csvname= 'Salesforce Objects.csv';
csvAttc.setFileName(csvname);
csvAttc.setBody(csvBlob);
Messaging.SingleEmailMessage email =new Messaging.SingleEmailMessage();
String[] toAddresses = new list<string> {'Enter your email address'};
String subject ='Salesforce Objects';
email.setSubject(subject);
email.setToAddresses( toAddresses );
email.setPlainTextBody('Salesforce Objects Name CSV');
email.setFileAttachments(new Messaging.EmailFileAttachment[]{csvAttc});
Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});

Change the toAddresses to your email address.

Thanks,
Maharajan.C