You need to sign in to do that
Don't have an account?
ran67
Getting the object name ,and field of that object using ID
Hi
I want to get the Objectname by using The Id ="a0190000003LIVw"
and i want to get the field of that spefic object .
cn u please help me to get this
List<Schema.SObjectType> gd = Schema.getGlobalDescribe().Values();
Map<String,String> objectMap = new Map<String,String>();
for(Schema.SObjectType f : gd)
{
objectMap.put(f.getDescribe().getKeyPrefix(), f.getDescribe().getName()));
}
ID sampleId ="a0190000003LIVw";
String prefix = sampleId.split(0,3);
String objectName = objectMap.get(prefix);
Map<String, Schema.SObjectField> desResult = Schema.getGlobalDescribe().get(objectName).getDescribe().Fields.getMap();
List<String> fieldList = new List<String>();
fieldList.addAll(desResult.keySet());
for(integer i =0;i<fieldList.size();i++)
System.debug(fieldList[i]);
All Answers
HI
please go through this link....
http://boards.developerforce.com/t5/Apex-Code-Development/How-to-get-the-object-API-name-by-Id/td-p/258323
http://boards.developerforce.com/t5/Apex-Code-Development/get-object-data-by-using-only-id-of-that-object/td-p/188408/page/2
I think ..Your problem will be solved ...
Did this post answers your questions...If so please mark it solved...so that Others get benifited...
Thanks
asish
For the getting the the object name
List<Schema.SObjectType> gd = Schema.getGlobalDescribe().Values();
Map<String,String> objectMap = new Map<String,String>();
for(Schema.SObjectType f : gd)
{
objectMap.put(,f.getDescribe().getKeyPrefix(), f.getDescribe().getName()));
}
ID sampleId ="a0190000003LIVw";
String prefix = sampleId.split(0,3);
String objectName = objectMap.get(prefix);
Similary you can get the fields of the object and then query it
Yaa I am getting the objectname but i want the fields of the object also how to query using the sobject
thanks for ur help'
Hi
Try this
For field .
For Query
RecordType rt = [SELECT Id,Name FROM RecordType WHERE SobjectType='Account' LIMIT 1];
For more Information please refer this link.....
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_sobject_describe.htm
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_fields_describe.htm
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_schema.htm
List<Schema.SObjectType> gd = Schema.getGlobalDescribe().Values();
Map<String,String> objectMap = new Map<String,String>();
for(Schema.SObjectType f : gd)
{
objectMap.put(f.getDescribe().getKeyPrefix(), f.getDescribe().getName()));
}
ID sampleId ="a0190000003LIVw";
String prefix = sampleId.split(0,3);
String objectName = objectMap.get(prefix);
Map<String, Schema.SObjectField> desResult = Schema.getGlobalDescribe().get(objectName).getDescribe().Fields.getMap();
List<String> fieldList = new List<String>();
fieldList.addAll(desResult.keySet());
for(integer i =0;i<fieldList.size();i++)
System.debug(fieldList[i]);
hi am not able to get the fields of that object.
i m getting error in this line
Compile Error: unexpected token: ','
objectMap.put(,f.getDescribe().getKeyPrefix(), f.getDescribe().getName()));
Please help me to get the field of that object.......
thanks in advance
objectMap.put(,f.getDescribe().getKeyPrefix(), f.getDescribe().getName()));
comma is present after opening parenthesis. For getting field I've posted the code in previous reply
Yaa i have kep t like that only but still am getting error . in that line .please look into it
Compile Error: expecting a right parentheses, found ','
objectMap.put(,f.getDescribe().getKeyPrefix(), f.getDescribe().getName()));
My bad!!! Please remove the comma and try to save it
how can i write a query to display the cureent account record details.
By using the Sobject.
Cont from Previous
Below we're creating a Query
String Query = 'SELECT ';
for(integer i =0;i<fieldList.size();i++)
Query += fieldList.get(i) + ',';
Query = Query.subString(0,Query.length()-1);
Query += ' FROM ' + objectName;
Now to run Query use Database.Query
List<Account> listAccount = Database.Query(Query);
Note i've used List<Account> you can't define something like List<objectName>. So before running the Query determine the object type
If i want to retrive only one Record. not list.that to only the current record am getting all the Record
how can i do it