You need to sign in to do that
Don't have an account?
newbee developer
Fetch RecordTypes based on loggedin user profile/permissions
Hi,
I want to fetch record types available for loggedin user from my object(in this case, its knowledge object).
Below is my query which is working fine but not based on permissions:
Now, I want to display those record types which are availble for loggedinuser profile. I want to display in a dropdown.
Please suggest how to check for loggedin user.
Thanks!
I want to fetch record types available for loggedin user from my object(in this case, its knowledge object).
Below is my query which is working fine but not based on permissions:
SELECT RecordType.Name,RecordType.Id,IsActive FROM RecordType where SobjectType = 'Knowledge__kav'
Now, I want to display those record types which are availble for loggedinuser profile. I want to display in a dropdown.
Please suggest how to check for loggedin user.
Thanks!
Hi newbie,
You can use the predefined method 'RecordTypeInfo' to get which record types are loggedin user. Start by calling DescribeSObjectResult.getRecordTypeInfos.
List<SelectOption> recordTypes = new List<SelectOption>();
for(RecordTypeInfo info: Account.SObjectType.getDescribe().getRecordTypeInfos()) {
if(info.isAvailable()) {
recordTypes.add(new SelectOption(info.getRecordTypeId(), info.getName()));
}
}
Inside the coding part use :
for( SelectOption selopt: recordTypes ) {
System.debug( selopt.getLabel() + ',' + selopt.getValue() );
}
Hope it Helps you. Mark this answer Solved if it resolves your query.
Regards ,
Suraj
All Answers
Hi newbie,
You can use the predefined method 'RecordTypeInfo' to get which record types are loggedin user. Start by calling DescribeSObjectResult.getRecordTypeInfos.
List<SelectOption> recordTypes = new List<SelectOption>();
for(RecordTypeInfo info: Account.SObjectType.getDescribe().getRecordTypeInfos()) {
if(info.isAvailable()) {
recordTypes.add(new SelectOption(info.getRecordTypeId(), info.getName()));
}
}
Inside the coding part use :
for( SelectOption selopt: recordTypes ) {
System.debug( selopt.getLabel() + ',' + selopt.getValue() );
}
Hope it Helps you. Mark this answer Solved if it resolves your query.
Regards ,
Suraj