You need to sign in to do that
Don't have an account?
Record Type Picklist
Hi All,
I have a requirement where in i have to show a picklist of record types on VF page based on the logged in user.The pick list should only display the case record types that the current user has permission to create cases.When user change the value in the picklist, then change the case record type field and refresh the entire page.Need help on the approach and any sample code reference.
I have a requirement where in i have to show a picklist of record types on VF page based on the logged in user.The pick list should only display the case record types that the current user has permission to create cases.When user change the value in the picklist, then change the case record type field and refresh the entire page.Need help on the approach and any sample code reference.
Try <apex:actionSupport event="onchange" action="{!Save}"/> instead of following on the Page -
<apex:actionSupport event="onchange" action="{!updateRecordType}"/>.
Save() is defined in the standard controller, you do not need to define it.
Else in Extension, if Save() did not worked, you may use this (changes on both Page and Extension to be done)-
In extension -
public case currentCase {get; set;}
public Case_RemoveMessageFlag(ApexPages.StandardController stdController) {
this.currentCase = [Select Id, RecordTypeId, SystemNote__c from Case where Id = :stdController.getRecord().Id limit 1];
}
public PageReference updateRecordType() {
update currentCase;
return null;
}
instead of -
private final Case currentCase;
public Case_RemoveMessageFlag(ApexPages.StandardController stdController) {
this.currentCase = [Select Id, SystemNote__c from Case where Id = :stdController.getRecord().Id limit 1];
}
public PageReference updateRecordType() {
this.currentCase.RecordTypeId = this.currentCase.RecordTypeId;
update this.currentCase;
return null;
}
and in Page -
<apex:inputField id="txt1" style="width:196px;" value="{!currentCase.RecordTypeId}" onchange="refreshPage()">
<apex:actionSupport event="onchange" action="{!updateRecordType}"/>
</apex:inputField>
instead of -
<apex:inputField id="txt1" style="width:196px;" value="{!case.RecordTypeId}" onchange="refreshPage()">
<apex:actionSupport event="onchange" action="{!updateRecordType}"/>
</apex:inputField>
All Answers
Have not tried this with RecordType but works with Owner for sure. Both Owner and RecordType are references to another object so should work with RecordType as well.
You may use either actionSupport or actionFunction to refresh the page. You will need to bind the method using onchange attribute of inputField. For sample code, see VisualForce Developer's Guide. It has pretty simple and good code examples.
If none of the answers helped you significantly, please post the solution. You may also mark your solution as the best answer.
<apex:inputfield> worked but than i need to pass the selected recordType to the controller and update the custom field on that case.
How do i send the Id of the record type to the controller and update the case custom field.
for e.g. if <apex:InputField value="{!c.RecordTypeId}"> is what you have used on Page, c.RecordTypeId in controller will give you the updated value that is currently selected on Page.
I tried to access the case recordTypeId in the class.But i get the recordTypeId which is already assigned to the custom field.Following the code i am trying:
Visualforce Page
<apex:page standardController="Case" extensions="Case_RemoveMessageFlag" showHeader="false" applyHtmlTag="false" applyBodyTag="false">
<script type="text/javascript">
function refreshPage()
{
window.top.location='/console';
}
</script>
<apex:form >
<apex:outputText style="font-weight: bold;" value="Case Record Type"></apex:outputText>
<br/>
<apex:inputField id="txt1" style="width:196px;" value="{!case.RecordTypeId}" onchange="refreshPage()">
<apex:actionSupport event="onchange" action="{!updateRecordType}"/>
</apex:inputField>
<br/>
<apex:commandButton rendered="{!HasMessage}" action="{!RemoveMessageFlag}" value="Clear Flag" id="theButton" onclick="refreshPage()"/>
</apex:form>
</apex:page>
Controller
public class Case_RemoveMessageFlag {
private final Case currentCase;
public Case_RemoveMessageFlag(ApexPages.StandardController stdController) {
this.currentCase = [Select Id, SystemNote__c from Case where Id = :stdController.getRecord().Id limit 1];
}
public boolean getHasMessage()
{
if(this.currentCase.SystemNote__c.contains('#NewMessage#') || this.currentCase.SystemNote__c.contains('#TaskCompleted#'))
return true;
return false;
}
public PageReference RemoveMessageFlag()
{
if(this.currentCase.SystemNote__c.contains('NewMessage#') || this.currentCase.SystemNote__c.contains('#TaskCompleted#'))
{
this.currentCase.SystemNote__c = '#';
update this.currentCase;
}
return null;
}
public PageReference updateRecordType()
{
this.currentCase.RecordTypeId = this.currentCase.RecordTypeId;
update this.currentCase;
return null;
}
}
And try using this -
public PageReference updateRecordType()
{
Save();
return null;
}
There is no save() method defined.
Try <apex:actionSupport event="onchange" action="{!Save}"/> instead of following on the Page -
<apex:actionSupport event="onchange" action="{!updateRecordType}"/>.
Save() is defined in the standard controller, you do not need to define it.
Else in Extension, if Save() did not worked, you may use this (changes on both Page and Extension to be done)-
In extension -
public case currentCase {get; set;}
public Case_RemoveMessageFlag(ApexPages.StandardController stdController) {
this.currentCase = [Select Id, RecordTypeId, SystemNote__c from Case where Id = :stdController.getRecord().Id limit 1];
}
public PageReference updateRecordType() {
update currentCase;
return null;
}
instead of -
private final Case currentCase;
public Case_RemoveMessageFlag(ApexPages.StandardController stdController) {
this.currentCase = [Select Id, SystemNote__c from Case where Id = :stdController.getRecord().Id limit 1];
}
public PageReference updateRecordType() {
this.currentCase.RecordTypeId = this.currentCase.RecordTypeId;
update this.currentCase;
return null;
}
and in Page -
<apex:inputField id="txt1" style="width:196px;" value="{!currentCase.RecordTypeId}" onchange="refreshPage()">
<apex:actionSupport event="onchange" action="{!updateRecordType}"/>
</apex:inputField>
instead of -
<apex:inputField id="txt1" style="width:196px;" value="{!case.RecordTypeId}" onchange="refreshPage()">
<apex:actionSupport event="onchange" action="{!updateRecordType}"/>
</apex:inputField>
Thanks.