• Ankitta Sharma
  • NEWBIE
  • 0 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
I have logged in as System Admin profile, In apex I wrote the code to
retrieve the selected record types of Account object. For example, in
account object I have 10 record types and I have selected only 5 record
types to one profile( X Profile). From the apex code, I want to retrieve
selected record types of Account object for specific profile( X Profile)

This is the code for current user profile record types. Now I want to get
the record types of specific profile. When I pass the profile Id, I want to
get the account object record types of that profile


public without sharing class SelectedRecordTypes {
public static List GetAvailableRecordTypeNamesForSObject( Schema
.SObjectType ObjType, Id profileId ) {
try {
User userId = [Select Id from User where Profile.Id =:profileId];
List names = new List();
List RecordTypes= new List();
List recTypeIds = new List ();
List infos = objType.getDescribe().getRecordTypeInfos();

// If there are 2 or more RecordTypes...
if (infos.size() > 1) {
for (RecordTypeInfo i : infos) {
if (i.isAvailable()
// Ignore the Master Record Type, whose Id always ends with
'AAA'.
// We check the Id because Name can change depending on the
user's language.
&& !String.valueOf(i.getRecordTypeId()).endsWith('AAA'))
names.add(i.getName());
}
}
// Otherwise there's just the Master record type,
// so add it in, since it MUST always be available
else names.add(infos[0].getName());
RecordTypes = [select Id, name from RecordType where Name IN :names];
for (RecordType rec : recordTypes) {
recTypeIds.add(rec.Id);
}
return RecordTypes;
} catch ( Exception recTypeException ) {
system.debug(':::::::::: recTypeException:'+recTypeException);
return null;
}
}
}

Is there any way to retrieve Selected record types of Specific profile on Specific Object?