function readOnly(count){ }
Don't have an account?
Search for an answer or ask a question of the zone or Customer Support.
You need to sign in to do that
Sign in to start searching questions
Signup for a Developer Edition
Sign in to start a discussion
@isTest public class MetadataFieldsTest { public static testmethod void testAll(){ try { MetadataFields objM = new MetadataFields(); objM.obj='contact'; objM.getobj(); objM.setobj('contact'); List<SelectOption> objList = objM.getobjs(); objM.fetchFields(); } catch(Exception ex){} } }
Try something like below,
Regards
Sampath
All Answers
I have created an Apex Class, some one please help me on creating Test Class. Thanks in Advance.
public class MetadataFields{
public String obj;
public List<String> objFields {get;set;}
public MetadataFields()
{
}
public String getobj()
{
return obj;
}
public void setobj(String obj)
{
this.obj = obj;
}
public List<SelectOption> getobjs()
{
List<Schema.SObjectType> gd = Schema.getGlobalDescribe().Values();
List<SelectOption> options = new List<SelectOption>();
for ( Schema.SObjectType f : Schema.getGlobalDescribe().values()){
if ( (f.getDescribe().getName() == 'Account') || (f.getDescribe().getName() == 'Contact') || (f.getDescribe().getName() == 'Lead') || (f.getDescribe().getName() == 'Opportunity')){
options.add(new SelectOption(f.getDescribe().getName(),f.getDescribe().getName()));
}
}
Options.Sort();
return options;
}
public void fetchFields()
{
List<String> fields = new List<String>();
Map<String , Schema.SObjectType> globalDescription = Schema.getGlobalDescribe();
System.debug('Selected Object is ' + obj);
Schema.sObjectType objType = globalDescription.get(obj);
System.debug('Object Type is ' + objType);
Schema.DescribeSObjectResult r1 = objType.getDescribe();
Map<String , Schema.SObjectField> mapFieldList = r1.fields.getMap();
for(Schema.SObjectField field : mapFieldList.values())
{
Schema.DescribeFieldResult fieldResult = field.getDescribe();
if(fieldResult.isAccessible())
{
System.debug('Field Name is ' + fieldResult.getName());
fields.add(fieldResult.getName());
}
}
List<String> so = new List<String>();
for(String f : fields)
{
so.add(f);
}
objFields = so;
}
}
Regards,
Mano
Try something like below,
Regards
Sampath
Thanks for your help. 100% Code Coverage. Can you please let me know your email id.
sampathjt@gmail.com