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
MVJMVJ 

Limit Pick list values

I created a Visual Force page to allow the user to modify the status of a Cases at the same time as creating a case note and adding an Enahncement Aproval to the case.  The enhancemnet approval is a custom object.

 

I have evrything working just fine with one small quirk.  On Cases you can have a huge list of status with a diffrent pick list for each record type. 

 

 When you go to the Visual Force page and select the Status dropdown it shows ALL the status values.  I want that limited to only the values for the Enhancemnt record type.

 

Can this be done?

 

Here is the VF Page:

 

 

<apex:page Controller="newEnhancemnetController" tabStyle="Case" id="thePage"> <script> function confirmCancel() { var isCancel = confirm("Are you sure you wish to cancel?"); if (isCancel) return true; return false; } </script> <apex:sectionHeader title="New Enhancemnet Approval" subtitle="for change board Case"/> <apex:form > <apex:pageBlock mode="edit"> <apex:pageMessages ></apex:pageMessages> <apex:pageBlockButtons > <apex:commandButton action="{!Save}" value="Save"/> <apex:commandButton action="{!Cancel}" value="Cancel" onclick="return confirmCancel()" immediate="true"/> </apex:pageBlockButtons> <apex:pageBlockSection title="Change Current Case Status" columns="1"> <apex:inputField value="{!Case.id}"/> <apex:outputField value="{!Case.subject}"/> <apex:inputField value="{!Case.status}" required="true"/> <apex:inputField value="{!Case.description}"/> </apex:pageBlockSection> <apex:pageBlockSection title="Add Enhancement Approval Information" columns="1"> <apex:inputField id="eaAprovedFor" value="{!EnhancementApproval.Approved_For__c}" required="true"/> <apex:inputField id="eaEnvironment" value="{!EnhancementApproval.Environment__c}" required="true"/> <apex:inputField id="eaValidFrom" value="{!EnhancementApproval.Valid_From__c}" required="true"/> <apex:inputField id="eaValidTo" value="{!EnhancementApproval.Valid_To__c}" required="true"/> </apex:pageBlockSection> <apex:pageBlockSection title="Add a Case Comment"> <apex:inputField id="caseComment" value="{!CaseComment.CommentBody}"/> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>

 

 Here is the controller:

 

 

public class newEnhancemnetController { Case oCase; Enhancement_Approval__c oEnahncemnetApproval; Contact contact; CaseComment casecomment; public Case getCase() { oCase = [select id, subject, status, description from Case where id = :ApexPages.currentPage().getParameters().get('id')]; if(oCase== null) oCase= new Case(); return oCase; } public Contact getContact() { if(contact== null) contact= new Contact(); return contact; } public CaseComment getCaseComment () { if(casecomment== null) casecomment= new CaseComment(); return casecomment; } public Enhancement_Approval__c getEnhancementApproval() { if(oEnahncemnetApproval== null) oEnahncemnetApproval= new Enhancement_Approval__c(); return oEnahncemnetApproval; } public PageReference cancel() { PageReference casePage = new ApexPages.StandardController(oCase).view(); casePage .setRedirect(true); return casePage ; } public PageReference Save() { //oEnahncemnetApproval.Case__c = oCase.id; //insert oEnahncemnetApproval; update oCase; //contact.accountid = '001Q0000005ktVx'; //insert contact; Enhancement_Approval__c oEA; oEA = new Enhancement_Approval__c(); oEA.Approved_For__c = oEnahncemnetApproval.Approved_For__c; oEA.Case__c = ApexPages.currentPage().getParameters().get('id'); oEA.Environment__c = oEnahncemnetApproval.Environment__c; oEA.Valid_From__c = oEnahncemnetApproval.Valid_From__c; oEA.Valid_To__c = oEnahncemnetApproval.Valid_To__c; insert oEA; if (casecomment.CommentBody != null){ casecomment.ParentId = ApexPages.currentPage().getParameters().get('id'); insert casecomment; } PageReference casePage = new ApexPages.StandardController(oCase).view(); casePage .setRedirect(true); return casePage ; } //*************************************************************************** //** Test Method //** //*************************************************************************** public static testMethod void testChangeBoardApproval() { pageReference p = Page.ChangeBoardApproval; p.getParameters().put('id', [select id from Case limit 1].id); test.setCurrentPage(p); newEnhancemnetController enhancemnetController = new newEnhancemnetController(); //enhancemnetController.cancel(); enhancemnetController.getCase(); enhancemnetController.getEnhancementApproval(); enhancemnetController.getContact(); enhancemnetController.getCaseComment(); enhancemnetController.save(); } }

 

 

 

 

Rajesh ShahRajesh Shah

Currently, as far as I know, there is no way to get a list of Picklist values for a record type. Using DescribeFieldResult, you could get the list of picklist values for Status field. And then there is another method called isActive for SchemaPicklistEntry. I am not sure if it returns true or false based on recordtype. You may try that out.

If that doesn't works, you will have to use selectList and selectOption to display only the required picklist values.

 

Also see the following link:

http://community.salesforce.com/sforce/board/message?board.id=Visualforce&thread.id=19403

Message Edited by Rajesh Shah on 12-08-2009 09:49 PM
uptime_andrewuptime_andrew

I believe using an extension, you can accomplish this.  Here are some snippets from what I was doing with an VF page for Opportunities:

 

 

VF page segment: 

 

 

<apex:pageBlockSectionItem > <apex:outputLabel value="{!$ObjectType.Opportunity.fields.StageName.label}" for="stageId"/> <apex:selectList value="{!opportunity.StageName}" id="stageId" size="1"> <apex:selectOptions value="{!newBusinessStageOptions}" /> <apex:actionSupport event="onchange" action="{!onStageChange}" rerender="theForm" /> </apex:selectList> </apex:pageBlockSectionItem>

 

 And then the newBusinessStageOptions list is defined in an extension:

 

 

public List<SelectOption> getNewBusinessStageOptions() { List<SelectOption> newBusinessStageOptions = new List<SelectOption>(); newBusinessStageOptions.add(new SelectOption('Qualifying Opp','Qualifying Opp')); newBusinessStageOptions.add(new SelectOption('Solution Discovery','Solution Discovery')); newBusinessStageOptions.add(new SelectOption('Technical POC','Technical POC')); newBusinessStageOptions.add(new SelectOption('Commercial Closing','Commercial Closing')); newBusinessStageOptions.add(new SelectOption('PO Approved','PO Approved')); newBusinessStageOptions.add(new SelectOption('Closed Won','Closed Won')); newBusinessStageOptions.add(new SelectOption('Closed Lost','Closed Lost')); return newBusinessStageOptions; }

 

Its a bit of a pain, because instead of conrolling the list from the Object > Fields section in Setup, you have to update the extension to add a new value.  However, assuming the options in Status change infrequently, it should be relatively painless after its setup :)