8

I want display the Record types which are accessible by logged in user profile in a VF page dropdown list. i used the below query, which returns me all types. and i could find a relationship between profile and recordType objects.Its not mentioned in the ER diagram as well.

**

SOQL:
select id,name from RecordType where sobjecttype='task' And isActive=true

**

is there any way to Retrieve the RecordType which are Accessible by Profile only. If not , Please let me know any work arounds if you know.

8

Use the RecordTypeInfo methods to determine which record types are available to a user. Start by calling DescribeSObjectResult.getRecordTypeInfos (or by ID or by name), iterate through each value, calling isAvailable() on each. This also automatically handles things like permission sets that a user might have, etc.

Example:

List<SelectOption> recordTypes = new List<SelectOption>();
for(RecordTypeInfo info: Account.SObjectType.getDescribe().getRecordTypeInfos()) {
    if(info.isAvailable()) {
        recordTypes.add(new SelectOption(info.getRecordTypeId(), info.getName()));
    }
}

// Include these next 3 lines to output the results during development and debugging
for( SelectOption selopt: recordTypes ) {
    System.debug( selopt.getLabel() + ',' + selopt.getValue() );
}
  • 2
    Would give +1 if you had code examples. This is pretty close to a link only answer as is. – Adrian Larson Sep 28 '15 at 18:14
  • Thanks for the Answer. describe call doesnt seems to be working for TASK object. Task.SObjectType.getDescribe(); – KrForce Sep 28 '15 at 18:17
  • 1
    @AdrianLarson You're absolutely right. I wasn't thinking. I've added such an example. – sfdcfox Sep 28 '15 at 18:17
  • 1
    @KrForce I'm guessing you have a variable named "task". Try Schema.Task.SObjectType.getDescribe().getRecordTypeInfos() instead. – sfdcfox Sep 28 '15 at 18:19
  • Perfect..works great for me. Thanks alot for your help. – KrForce Sep 28 '15 at 18:52

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.