+ Start a Discussion
yunicfayunicfa 

how to get description of sobject or field from apex

hello averybody.

i need someone say me how i can get the description to sobject or field from apex.
there is Schema.DescribeSObjectResult and Schema.DescribeFieldResult but they dont give a method as getDescription().
my best regard! i hope that someone help me with that !

Vinita_SFDCVinita_SFDC

Hello,

 

Yes the method getDesciption is available for different contexts. For example:

 

for(DescribeDataCategoryGroupResult singleResult : describeCategoryResult){

//Getting description
singleResult.getDescription();
//Getting the sobject
singleResult.getSobject();
}

 

For details please refer the section "Understanding Apex Describe Information" under "Dynami Apex" section in the following link:

 

http://www.salesforce.com/us/developer/docs/apexcode/

 

 

 

yunicfayunicfa

thnx for reply.

 

i walked trough your answer before post my question .. and i didnt get any result ! .. please can you tell me hw i can get the description for example 

Custom Object  Exam  with Field  Description  and the description of this field is  Description of field 

Hw i can get the string  Description of field  using your solution 

 

Thnx a lot !

sandeep@Salesforcesandeep@Salesforce

  Below Link would be helpful for you : Understanding Apex Describe Information - Salesforce.com

Devender MDevender M
Hi yunicfa,

Here you will get all the fields API.

String sfields= '';
Map<String, Schema.SObjectField> objectFieldMap = Schema.getGlobalDescribe().get('ObjectAPI').getDescribe().fields.getMap();
for(Schema.SObjectField column: objectFieldMap.values()) {
sQuery += column+', ';
}
system.debug(sfields); // here u can see all fields API.
yunicfayunicfa
i dont understand your code !
where did u use sfileds ???? in

Map objectFieldMap =
Schema.getGlobalDescribe().get('ObjectAPI').getDescribe().fields.getMap();
for(Schema.SObjectField column: objectFieldMap.values()) {
sQuery += column+', ';
}


*
*
* Yunier Cordovi Figueroa*
SKYPLANNER TEAM
www.theskyplanner.com
209.878.7363
ycordovi@theskyplanner.com
8180 NW 36 St, Suite 422 Doral, FL 33166


Devender MDevender M
u can try this sfields is used to store the api names of the fields.
String sfields= '';
Map<String, Schema.SObjectField> objectFieldMap = Schema.getGlobalDescribe().get('ObjectAPI').getDescribe().fields.getMap();
for(Schema.SObjectField column: objectFieldMap.values()) {
sfields+= column+', ';
}
system.debug(sfields); // here u can see all fields API.
yunicfayunicfa

its not works for me .. coz i need the drescription not the names ! htnx anyway ! 

Devender MDevender M
Hi yunicfa,

i have misunderstand before, now you can try this code.

Map<String, Schema.SObjectField> objectFieldMap = Schema.getGlobalDescribe().get('Contact').getDescribe().fields.getMap();

List<String> fieldList =new List<String>();
for(String fieldName:objectFieldMap.keySet()) {
Schema.DescribeFieldResult fieldDescribe = objectFieldMap.get(fieldName).getDescribe();
system.debug('fieldDescribe --->' +fieldDescribe );
fieldList.add(fieldDescribe.getName());
}
Tristyn MaaloufTristyn Maalouf
You can gather the decriptions for all fields on an object using the Tooling API with the following query. Just use whatever object's API name you need for EntityDefinition.QualifiedAPIName.
ToolingAPI query
Make sure you have 'Use Tooling API' selected. To run this query via apex and deserialize the results so that you can access them in Apex see https://github.com/CompassionIntl/SalesforceSchemaAuditor/blob/master/classes/FieldAuditor.cls