-1

So I am trying to create a feature that will allow users to search external databases to add accounts to salesfoce, and if not found they can create the account from scratch. However the org I am developing in has many different user profiles that determine which account record types they have access too.

Is there any way to query the available account record types based on a profile ID? I have been searching online but the only solutions I have found have been to hard code values, but as there are about a dozen profiles and account record types that doesn't seem like the best option for me. If anyone has any suggestions as to how to query account record types available for a specific profile, any help would be greatly appreciated. (I've been using userinfo.getProfileId() to get the users profile, but the queries I have been doing will only return the record types of ALL accounts in the org)

1 Answer 1

3

You can use the RecordTypeInfo class to determine which record types a user has access to. You can use it like this:

SelectOption[] options = new SelectOption[0];
for(RecordTypeInfo info: Schema.Account.SobjectType.getDescribe().getRecordTypeInfos()) {
    if(info.isAvailable()) {
        options.add(new SelectOption(info.getRecordTypeId(), info.getName()));
    }
}

What you'll get is a list suitable for an apex:selectList or apex:selectRadio, etc.

2
  • That only tells you availability for the running user, not an arbitrary profile?
    – Adrian Larson
    Aug 7, 2018 at 18:04
  • @AdrianLarson Yes, the OP specified they're using UserInfo.getProfileId, which sounds like this is what they want. Also, more specifically, I'm not aware of any way short of using the Metadata API to get the visbilities configured for any arbitrary profile, since there's no SOAP-based object you can query on.
    – sfdcfox
    Aug 7, 2018 at 18:25

You must log in to answer this question.

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