function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sfdeveloper9sfdeveloper9 

Record Types question

Is there a way in apex to know what record types the logged in user has access to on particular object?

Thanks.

Best Answer chosen by Admin (Salesforce Developers) 
pankaj.raijadepankaj.raijade

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_sobject_describe.htm#apex_recordTypeInfo_methods

 

 

This should help you. Check out method 'isAvailable'.

 

Regards,

Pankaj Raijade.

 

 

 

All Answers

pankaj.raijadepankaj.raijade

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_sobject_describe.htm#apex_recordTypeInfo_methods

 

 

This should help you. Check out method 'isAvailable'.

 

Regards,

Pankaj Raijade.

 

 

 

This was selected as the best answer
Pradeep_NavatarPradeep_Navatar

Standard object and custom objects have a share object in which access level fields tells you which user can access the objects. First of all object_share object having three fields accesslevel, Userorgroupid and parentid. You can assign Userorgroupid with the  logged-in user and parent id refer the id of object and access level takes a picklist values "edit", "Readonly" values. You have to DO a SOQL query on record type and bind the particular object with it. Tryout the code snippet given below :

 

        RecordType RecTypeOrg = [Select Id, Name from RecordType where name ='Individual' limit 1];

        Account accInd = [Select Id, Name,RecordTypeId from Account where RecordTypeId =:RecTypeOrg.id  limit 1];

        accountshare accshare = [select AccountAccessLevel,UserOrGroupId,AccountId from accountshare where UserOrGroupId =: userinfo.getuserid() and accountid=:accInd.id];

        system.debug(' Access level ' +  accshare.AccessLevel);

         Note: In case of custom object, parentid field and access level field will work.