You need to sign in to do that
Don't have an account?
N>Help Creating Test Class for Retrieving Field Names
I'm used to making test classes for inserting data in Objects but I'm kinda lost in making test data for this code...
(It retrieves the custom field names of my Custom Object mMovie__c)
public class objectlist {
public List<string> fieldLabel {get;set;}
public objectlist()
{
this.getAccountFields();
}
public void getAccountFields()
{
Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();
fieldLabel = new List<string>();
Map <String, Schema.SObjectField> fieldMap = gd.get('mMovie__c').getDescribe().fields.getMap();
for(Schema.SObjectField fieldAPI : fieldMap.values())
{
// if(fieldAPI.getDescribe().isCustom() )
//{
fieldLabel.add(fieldAPI.getDescribe().getLabel());
//}
}
fieldLabel.sort();
system.debug('fieldLabel-----'+fieldLabel);
}
}
(It retrieves the custom field names of my Custom Object mMovie__c)
public class objectlist {
public List<string> fieldLabel {get;set;}
public objectlist()
{
this.getAccountFields();
}
public void getAccountFields()
{
Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();
fieldLabel = new List<string>();
Map <String, Schema.SObjectField> fieldMap = gd.get('mMovie__c').getDescribe().fields.getMap();
for(Schema.SObjectField fieldAPI : fieldMap.values())
{
// if(fieldAPI.getDescribe().isCustom() )
//{
fieldLabel.add(fieldAPI.getDescribe().getLabel());
//}
}
fieldLabel.sort();
system.debug('fieldLabel-----'+fieldLabel);
}
}
Hi
since you are not using any data in your class you dont have to create any data to test the class , just use below code . it will give 100% coverage .
All Answers
Hi
since you are not using any data in your class you dont have to create any data to test the class , just use below code . it will give 100% coverage .