function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
icemft1976icemft1976 

Record Type field filtering & NEW override

I'm overriding the Cases NEW button,and when people get to my visualforce page (after selecting the appropriate Case recordtype) the Type picklist in not filtered.

 

They see all the possible Types  even though the RecordTypeId parameter is being passed in the url and I can confirm it's there (by outputting the field value). 

 

Is there a trick with overriding New and retaining the Record Type field filtering? Common problem? If i use the same page and just make it an edit page, the Type values filter based on Record Type correctly.

 

Here's my code:

 

Page:

 

<apex:page standardController="Case" action="{!initialize}" extensions="CaseControllerExtension" >

   <style>
    textarea {width:100%;}
   </style>


    <apex:sectionHeader title="New Case" />
    <apex:form >
        <apex:pageBlock id="caseInputForm" mode="edit"  >   
        <apex:pageBlockButtons location="bottom">
                <apex:commandButton title="Continue" value="Continue" rendered="{! !continueTest}" action="{!continueForm}" reRender="caseInputForm" />
                <apex:commandButton value="Submit Ticket" action="{!save}" disabled="{! !continueTest}"/>
                <apex:commandButton value="Cancel" action="{!cancel}"/>              
        </apex:pageBlockButtons>  
            <apex:pageBlockSection columns="1" rendered="{!CountOutstandingIssues != 0 && continueTest == false}">
                <apex:pageMessage escape="false" severity="INFO" strength="3" summary="ATTENTION! The IT Team is 
                currently working on a known problem, before you submit this case read the message(s) below and 
                then select 'continue' if your issue is different."  />
            </apex:pageBlockSection>
            <apex:pageBlockSection ><apex:pageMessages ></apex:pageMessages></apex:pageBlockSection>
            <apex:pageBlockSection columns="1" rendered="{!CountOutstandingIssues == 0 || continueTest == true}">
                <apex:inputField value="{!case.ContactId}" required="true"/>
                <apex:inputField value="{!case.Priority}"/>
                <apex:inputField value="{!case.Type}"/>
                <apex:inputField value="{!case.Problem_Detail__c}"/>
                <apex:inputField value="{!case.Description}"/>
            </apex:pageBlockSection>
               
            <apex:pageBlockSection title="IT Admin Section" rendered="{!continueTest && ($Profile.Name == 'System Administrator' || $Profile.Name == 'IT User')}">         
                <apex:inputField value="{!case.Status}"  />
                <apex:inputField value="{!case.Origin}"  />
                <apex:inputField value="{!case.Subject}"/>
                <apex:inputField value="{!case.Follow_Up_Date__c}"  />
                <apex:inputField value="{!case.Systemwide_Issue__c}"/>
                <apex:inputField value="{!case.Systemwide_Issue_Message__c}"/>
            </apex:pageBlockSection>             
        </apex:pageBlock>
    </apex:form>
</apex:page>

 

Controller

 

public class CaseControllerExtension {
    
    public Map<String, String[]> details = new Map<String, String[]>();
    public Case newCase {get;set;}
    public Boolean continueTest = false;  
    
    public CaseControllerExtension (Case c)
    {
        newCase = c;
        init();
    }
        
    public CaseControllerExtension (ApexPages.StandardController stdController) {
        this.newCase = (Case)stdController.getRecord();
        init();  
    }
    
    private void init()
    {
        newCase.Status = 'New';
        newCase.Priority = 'Medium';
        newCase.Origin = 'Web';
    }

    public PageReference initialize() {
        
        if(newCase.RecordTypeId == null)
        {
            Map<String, String> params = ApexPages.currentPage().getParameters();
            String paramString = '/500/e?nooverride=1';
            
            for(String key: params.keySet())
            {
               paramString = paramString + '&' + key + '=' +  params.get(key);
            }             
            return new PageReference(paramString);
        }
        else if(newCase.RecordTypeId != '01230000000DMGk')
        {
            Map<String, String> params = ApexPages.currentPage().getParameters();
            String paramString = '/500/e?nooverride=1&RecordType=' + newCase.RecordTypeId;

            if(params.containsKey('sfdc.override'))
            {
                params.remove('sfdc.override');
            }
            
            if(params.containsKey('save_new'))
            {
                params.remove('save_new');
            }

            if(params.containsKey('save_new_url'))
            {
                params.remove('save_new_url');
            }

            for(String key: params.keySet())
            {
               paramString = paramString + '&' + key + '=' +  params.get(key);
            }        
            return new PageReference(paramString);
        }


        User u = [select Id,Email from User where Id = :UserInfo.getUserId()]; 
        if([select count() from Contact where Email = :u.Email] != 0)
        {
            Contact c = [select Id, Email from Contact where Email = :u.Email];  
            newCase.ContactId = c.Id;
        }
                        
        if(getCountOutstandingIssues() == 0 )
        {
            continueTest = true;
        }
        for (Case outstandingIssue: [Select Id, Subject, Systemwide_Issue__c,Systemwide_Issue_Message__c, Status from Case where Systemwide_Issue__c = true])
        {
            if(outstandingIssue.Systemwide_Issue_Message__c != null)
            {
                ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.INFO, outstandingIssue.Systemwide_Issue_Message__c);
                ApexPages.addMessage(myMsg);
            }
        }
        return null;
    }
    
    public Boolean getcontinueTest() {
        return continueTest;
    } 

    public PageReference continueForm() {
        continueTest = true;
        return null;
    }
    
    public Integer getCountOutstandingIssues() {
        return [Select count() from Case where Systemwide_Issue__c = true];
    }
    
    public PageReference save()
    {
        
        //Logical actions
       database.DMLOptions dmo = new database.DMLOptions();
       dmo.AssignmentRuleHeader.useDefaultRule = true;
       dmo.EmailHeader.triggerUserEmail = true; 
       dmo.EmailHeader.triggerAutoResponseEmail = true;
       newCase.setOptions(dmo);
       
       try (
           Database.SaveResult MySaveResult = Database.Insert(newCase, false);
           return new PageReference( '/cases/casesavedjump.jsp');
       } catch Exception (e) {
           ApexPages.addMessages(e);
           return null;
       }
    }
}