+ Start a Discussion
Anuj Joshi 42Anuj Joshi 42 

Covering FLS is createable and isUpdateable conditions in test class

Hi All,

I am checking in my class whether the fields of object are createable. I am using this condition in the objects. I am using Schema.sObjectType.Case.fields.fieldname.isCreateable in the if loop. I have 10 fields like this for which I am checking. For this if loop the code is not getting covered in the test class. 
I have tried to run as system admin using system.runAs() but that ios also not covering the test class.

sachin kadian 5sachin kadian 5

I am not sure if i got your requiremnt correct but i tried below code and its working fine for me and returning 100% test coverage.
public class ForumQuestion {
    public ForumQuestion(){
        List<String> fieldNames = new List<String>{'FirstName','Email','LastName'};
            Map<String,Schema.SObjectField> fieldsMap= Schema.sObjectType.Contact.fields.getMap();
            for(String f : fieldNames){
                    System.debug('field '+f+ ' is Updatable ');

Test Class- 
public class Test_ForumQuestion {
    public static testMethod void test_forumQuestionConstructor(){
        new ForumQuestion();