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
asadimasadim 

Get object from object name

Hi,

 

Is there a way to get the actual object using the object name?

 

Thanks.

GoodGrooveGoodGroove

If you are using a controller extension try

 

myObject__c o = (myObject__c).controller.getRecord();

 

 

 

asadimasadim
Thanks but that doesn't do what I want. I have the object name (it's a String value) not the actual object.
GoodGrooveGoodGroove
How do you identify the current object, it is stored as a string, but is it set dynamically or is it static?
arunkarunk

Hi,

 

 

This what u want?

 

String name = 'My Object Name'; 

[Select id, name from My_Custom_Object__c where name:=name] 

 

This will work if you know which object type you want. If you just have name and don't know what object it is, then  its useless. We can retrieve a record without knowing its type only with ID and not name.

 

Regards,

Arun.