2

I have custom visualforce page for record type selection (custom button on custom object to create a new record - when user clicks on the button, it will navigate to record type selection page) Record type selection page is showing all record types irrespective of user's profile visibility at record type level. I would like to control / display only record types based on Users Profile i.e. if there are 3 record types available on custom object, based on users login profile, has to see record types (for example 2 record types only) Note: wrote 'with sharing apex controller' - it is not working as expected.

Below is my code (Apex Controller)

public with sharing class  recTypeSelInterventions {

  public recTypeSelInterventions (ApexPages.StandardSetController controller)   
   {
 public list<RecordType> getRecordTypes()
   {
     RecordTypes = [select Id, Name, Description, IsActive from RecordType where sObjectType='Interventions__c' and IsActive!=False ORDER by Name];
     return RecordTypes;

   }

/************getselop method displays record type picklist values ******************/  
   public List<selectOption> getselop()
     {
        List<SelectOption> options = new List<SelectOption>();

     Schema.DescribeSObjectResult d = Schema.SObjectType.Interventions__c; 
     Map<Id,Schema.RecordTypeInfo> rtMapById = d.getRecordTypeInfosById();

      for(id rtId: rtMapById.keyset())
       {
            if(rtMapById.get(rtId).getName() != 'Master')
             {
                options.add(new selectoption(rtId,rtMapById.get(rtId).getName()));   
                mapRTIdAndName.put(rtId,rtMapById.get(rtId).getName()); 
                mapRTNameAndId.put(rtMapById.get(rtId).getName(),rtId);         
              }            
       }        
        return options;
   }  

Visualforce Page:

<apex:page standardController="customObj__c" extensions="recTypeSelInterventions" recordSetvar="Interventions" >
<apex:sectionHeader subtitle="Select Intervention Record Type" title="New Intervention"  />
<apex:outputLabel >Select a record type for the new intervention. To skip this page in the future, change your record type settings 
                   on your personal setup page.
</apex:outputLabel>
<br/><br/>  
<apex:messages />


    <apex:form >
        <apex:pageblock title="Select Record Type">
            <apex:pageBlockSection >
                <apex:pageBlockSectionItem >
                    <apex:outputLabel > Record Type of new record </apex:outputLabel>
                    <apex:selectList value="{!selected}" size="1" required="true">
                        <apex:selectOptions value="{!selop}">
                        </apex:selectOptions>
                    </apex:selectList>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
            <apex:pageblockButtons location="bottom" >
               <apex:commandButton value="Continue" action="{!Continuous}"/>
                <apex:commandButton value="Cancel" action="{!cancel}"/>
            </apex:pageblockButtons>
        </apex:pageblock>

        <apex:outputLabel value="Available Intervention Record Types" style="font-weight:bold" />
        <br/><br/> 
            <apex:dataTable value="{!RecordTypes}" var="RecordType" columns="2" Border="1" cellpadding="1" >
                <apex:column >
                    <apex:facet name="header">Record Type Name</apex:facet>
                    <apex:outputText value="{!RecordType.Name}" style="font-weight:bold"> </apex:outputText>
                </apex:column>
                <apex:column >
                    <apex:facet name="header">Description</apex:facet>
                    <apex:outputText value="{!RecordType.Description}"> </apex:outputText>
                </apex:column>
   </apex:dataTable>

    </apex:form>
</apex:page>

Thanks in advantage for any advice.

  • It would help attract more answers if you shared the relevant parts of your code (VF and Page) with us here. – Sebastian Kessel Apr 18 '16 at 15:14
  • public with sharing class recTypeSelInterventions { – Kiran Kulakarni Apr 18 '16 at 15:39
  • public list<RecordType> getRecordTypes() { RecordTypes = [select Id, Name, Description, IsActive from RecordType where sObjectType='Interventions__c' and IsActive!=False ORDER by Name]; return RecordTypes; } public List<selectOption> getselop() { List<SelectOption> options = new List<SelectOption>(); Schema.DescribeSObjectResult d =Schema.SObjectType.Interventions__c; Map<Id,Schema.RecordTypeInfo> rtMapById = d.getRecordTypeInfosById(); for(id rtId: rtMapById.keyset()) { – Kiran Kulakarni Apr 18 '16 at 15:44
  • if(rtMapById.get(rtId).getName() != 'Master') { options.add(new selectoption(rtId,rtMapById.get(rtId).getName())); mapRTIdAndName.put(rtId,rtMapById.get(rtId).getName()); mapRTNameAndId.put(rtMapById.get(rtId).getName(),rtId); – Kiran Kulakarni Apr 18 '16 at 15:44
  • <apex:form > <apex:pageblock title="Select Record Type"> <apex:pageBlockSection > <apex:pageBlockSectionItem > <apex:outputLabel > Record Type of new record </apex:outputLabel> <apex:selectList value="{!selected}" size="1" required="true"> <apex:selectOptions value="{!selop}"> </apex:selectOptions> </apex:selectList> </apex:pageBlockSectionItem> </apex:pageBlockSection> – Kiran Kulakarni Apr 18 '16 at 15:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.