1

How do I check the access of current user on particular object dynamically. I have a custom mapping object in that I am storing object name in the string. I want to check Whether the current user has access to that object or not. Like this

Schema.sObjectType.Account.isCreateable()

instead of account there can be any name. like

Schema.sObjectType.customobject1.isCreateable();
Schema.sObjectType.customobject2.isCreateable();

& to convert I used this code

// I have Account name in String
String objectStr = 'Account';

// Convert to schema.sObjectType
Schema.SObjectType convertType = Schema.getGlobalDescribe().get(objectStr);

Still It is giving error like

Method does not exist or incorrect signature: Schema.sObjectType.convertType.isCreateable()

Please Guide me!

Thanks in advance!

1
  • I guess you are converting the objectStr value i.e Account, not the type of Object. Try with type of object.
    – Vickal
    Commented Sep 11, 2015 at 6:55

1 Answer 1

1

EDIT

I tried the below code for both standard and custom object and it is working in both cases for me. hope this helps.

Standard Object

Schema.DescribeSObjectResult drSObj = Schema.sObjectType.Account;
System.debug(drSObj.getChildRelationships());
System.debug(drSObj.getRecordTypeInfos());
System.debug(drSObj.getRecordTypeInfosByID());
System.debug(drSObj.getRecordTypeInfosByName());
System.debug(drSObj.isCreateable());
System.debug(drSObj.isAccessible());
System.debug(drSObj.isUpdateable());
System.debug(drSObj.isDeletable());
System.debug(drSObj.isFeedEnabled());

Custom Object

Schema.DescribeSObjectResult drSObj = Schema.sObjectType.Book__c;
System.debug(drSObj.getChildRelationships());
System.debug(drSObj.getRecordTypeInfos());
System.debug(drSObj.getRecordTypeInfosByID());
System.debug(drSObj.getRecordTypeInfosByName());
System.debug(drSObj.isCreateable());
System.debug(drSObj.isAccessible());
System.debug(drSObj.isUpdateable());
System.debug(drSObj.isDeletable());
System.debug(drSObj.isFeedEnabled());

Updated Code

Dynamically from from Object Name

String objectStr = 'Account';
Schema.SObjectType convertType = Schema.getGlobalDescribe().get(objectStr);
Schema.DescribeSObjectResult drSObj = convertType.getDescribe();
System.debug('######'+drSObj.isCreateable());
3
  • can you add these two lines above the code
    – Shilpa
    Commented Sep 11, 2015 at 7:32
  • String objectStr = 'Account'; Schema.SObjectType convertType = Schema.getGlobalDescribe().get(objectStr); Schema.DescribeSObjectResult drSObj = Schema.sObjectType.convertType;
    – Shilpa
    Commented Sep 11, 2015 at 7:32
  • See my updated code.
    – Saroj Bera
    Commented Sep 11, 2015 at 7:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .