You need to sign in to do that
Don't have an account?
Retrieving all Object Names and its field names on selection by user
hi all,
i wanna retrieve all the objects' names (display that to the user) and fields from the object name (chosen by the user). To get the object name, i am tryin to use the describe methods like below:
1. describeGlobal()
2. describeDataCategoryGroups()
3. describeDataCategoryGroupStructures()
4. describeLayout()
5. describeSObject()
6. describeSObjects()
7. describeSoftphoneLayouts()
8. describeTabs()
i cant use these methods in salesforce Class page. if i use these methods, it is throwing me some error like
Error: Compile Error: Method does not exist or incorrect signature: connection.describeGlobal()
and more errors similar to the above ones.. what i have to do to resolve this problem, how should i make use of these default methods provided for salesforce.? please help and guide me how to use these methods to retrieve the object names and its fields on the selection of the object?
is there any other syntax or method available for taking the object name and again taking the fieldname to show from the DataBase? help me in doing this
Thanks,
abivenkat,
SFDC Learner.
Try this code. You can also try to run it in Eclipse Execute Anonymous. It will show there the result of the code below.
List<Schema.SObjectType> gd = Schema.getGlobalDescribe().Values();
List<SelectOption> options = new List<SelectOption>();
for(Schema.SObjectType f : gd)
{
options.add(new SelectOption(f.getDescribe().getLabel(),f.getDescribe().getLabel()));
system.debug (f.getDescribe().getnamel() + '**********' +f.getDescribe().getLabel());
}
Ooopss... I didnt see you need also the field names... here is the complete code..
List<Schema.SObjectType> GD = Schema.getGlobalDescribe().Values();
for(Schema.SObjectType ObjTyp : GD) {
Schema.DescribeSObjectResult Obj = ObjTyp.getDescribe();
System.debug(' **********************************************NAME: ' + obj.GetLabel() + ' API : ' + Obj.GetName());
Map<String, Schema.SObjectField> objFields = Obj.fields.getMap();
for(String fieldName : objFields.keySet()){
schema.SobjectField s = objFields.get(fieldname);
DescribeFieldResult x = s.getDescribe();
system.debug('FIELD: ' + fieldname + ' NAME: ' +x.getlabel());
}
}
hi eugene_bm,
actually, i dont have any idea about this code. my functionality is
1. i have to show all the objects to the user in my first picklist and let them choose one from it.
2. then, i have capture the user's selection and retrieve the fields for that particular object.
3. then only i have to perform my remaining operation.
i have already retrieved the object's names and populated in the selectlist and i am getting the chosen object to the controller. now i dont know how to retrieve the fields for the chosen object. now i am stuck in this.. i think the code u have provided me, it will perform the whole thing in a single event, but, i wanna perform those step by step..
thanks,
abivenkat,
SFDC Learner
hi eugene_bm,
i have a soql query as
Select FieldName from ObjectName where FieldName = 'sample'
i want not only the values for this query, but, also the field names for these records. how can i construct my soql query and run?? please help...
thanks,
abivenkat,
SFDC Learner
As far as I know, You can't query the fields of an object, only its values.
For the below questions:
1. i have to show all the objects to the user in my first picklist and let them choose one from it.
- You can manipulate the code i gave above. Make it a class that return a list of objects. Call it in your page.
2. then, i have capture the user's selection and retrieve the fields for that particular object.
- Do it also here.
3. then only i have to perform my remaining operation.