You need to sign in to do that
Don't have an account?
Jamsie
Access available Record Types from a Profile
Hi Everyone.
I've built a page to allow users to select a Case Record Type from a favourites list or all Case Record Types. It works well except the All Case Types list shows all the Case Record Types in our org rather than those normally accessible to the current user.
My question: how can I access the list of Case Record Types available to the user from their Profile in my controller?
Thanks in advance,
James.
Thank you code the cloud. :smileyvery-happy:
After a bit of mind twisting it was quite simple. Here's my code...
//Get list of available Case Record Types to be used in the CaseType list
public List<SelectOption> getCaseTypes() {
List <RecordType> rl;
List<SelectOption> sol = new List<SelectOption>();
rl = [select Id, Name from RecordType where sObjectType='Case' and isActive=true];
Schema.DescribeSObjectResult d = Schema.SObjectType.Case;
Map<Id,Schema.RecordTypeInfo> rtMapById = d.getRecordTypeInfosById();
sol.add(new SelectOption('','-- Select a Case Type --'));
if(listView=='F'){
Set<String> favSet = new Set<String>();
List<Team_Member__c> tm = new List<ATS_Team_Member__c>();
tm = [select id, User_Reference__c, Favourite_Case_Types__c
from Team_Member__c
where User_Reference__c = :UserInfo.getUserId()
limit 1];
if(tm.size()>0){
System.debug('-- customSelector - Favourites: ' + tm[0].Favourite_Case_Types__c);
List<String> favList = tm[0].Favourite_Case_Types__c.split(';');
favSet.addAll(favList);
}
for (RecordType r : rl) {
if(favSet.contains(r.Name){
sol.add(new SelectOption(r.id,r.Name));
}
}
}else if(listView=='A'){
for (RecordType r : rl) {
if(rtMapById.get(r.id).isAvailable()){
sol.add(new SelectOption(r.id,r.Name));
}
}
}
return sol;
}
All Answers
James,
Take a look at the docs:
http://www.salesforce.com/us/developer/docs/api/index_Left.htm#StartTopic=Content/sforce_api_calls_describesobjects_describesobjectresult.htm#i1428028
if you look at the describeSobjectResult, there is an array of recordTypeInfos[]. Each of the RecordTypeInfo objects has an available attribute that should allow you to dynamically add it to your list of case types for the user.
Thank you code the cloud. :smileyvery-happy:
After a bit of mind twisting it was quite simple. Here's my code...
//Get list of available Case Record Types to be used in the CaseType list
public List<SelectOption> getCaseTypes() {
List <RecordType> rl;
List<SelectOption> sol = new List<SelectOption>();
rl = [select Id, Name from RecordType where sObjectType='Case' and isActive=true];
Schema.DescribeSObjectResult d = Schema.SObjectType.Case;
Map<Id,Schema.RecordTypeInfo> rtMapById = d.getRecordTypeInfosById();
sol.add(new SelectOption('','-- Select a Case Type --'));
if(listView=='F'){
Set<String> favSet = new Set<String>();
List<Team_Member__c> tm = new List<ATS_Team_Member__c>();
tm = [select id, User_Reference__c, Favourite_Case_Types__c
from Team_Member__c
where User_Reference__c = :UserInfo.getUserId()
limit 1];
if(tm.size()>0){
System.debug('-- customSelector - Favourites: ' + tm[0].Favourite_Case_Types__c);
List<String> favList = tm[0].Favourite_Case_Types__c.split(';');
favSet.addAll(favList);
}
for (RecordType r : rl) {
if(favSet.contains(r.Name){
sol.add(new SelectOption(r.id,r.Name));
}
}
}else if(listView=='A'){
for (RecordType r : rl) {
if(rtMapById.get(r.id).isAvailable()){
sol.add(new SelectOption(r.id,r.Name));
}
}
}
return sol;
}