Need urgent Help I am executing the following code in execute anonymous.

String objtype = 'Lead';

 SObject objToBeCreated ;
        if(objtype == 'User')
           objToBeCreated = new User();
        if(objtype == 'Lead')
           objToBeCreated = new Lead();
        if(objtype == 'Accont')
           objToBeCreated = new Account();

       Schema.sObjectType sobject_type = objToBeCreated.getSObjectType(); 

     Schema.DescribeSObjectResult sobject_describe = sobject_type.getDescribe(); 
Map<String, Schema.SObjectField> field_map = sobject_describe.fields.getMap(); 

 for(String fName : field_map.keySet())

I am getting all he fields but there are 4 picklist fields which I am not getting. Can anyone please help in this matter.

  • I am getting all the picklist field names using your code. – Lance Shi Oct 26 '16 at 3:46

The problem is that the context user doesn't have the field level permission for those fields.

If you update the user's profile to have access to those fields, you will start to get those fields returned in your anonymous script.

Note that this needs to be done even if the user is the system admin.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.