+ Start a Discussion
Amita TatarAmita Tatar 

getting record type based picklist values

Hi all,

I have four record types on order object. I have overridden them with the visualforce pages,but i am not able to see the picklist values based on the selected record types. Can you please guide me?
--This is my controller--
public class OrderRedirectExtensionController{
public String strRecordTypeId{get;set;}
public Order orderObj{get;set;}
public RecordType recordType{get;set;}
List<RecordType> lstred{get;set;}
public OrderRedirectExtensionController(ApexPages.StandardController controller ){
strRecordTypeId= apexpages.currentpage().getparameters().get('RecordType');

Order orderObj = new Order();
orderObj.RecordTypeId = strRecordTypeId;

system.debug('****strRecordTypeId*********'+strRecordTypeId);
lstred=[select id,Name from RecordType where id=:strRecordTypeId];
system.debug('****lstred*********'+lstred);
if(lstred.size()>0){

recordType=lstred[0];
  }
}
public PageReference saveOrder(){
 insert orderObj ;
 PageReference pageRef = new PageReference('/'+orderObj.id);
 pageRef.setRedirect(true); 
 return pageRef ;

}
}


--This is my page---
<apex:page standardController="Order" showHeader="true">
<apex:form >
<apex:messages />
 <style>
 .activeTab {background-color: #236FBD; color:white;
 background-image:none}
 .inactiveTab { background-color: lightgrey; color:black;
  background-image:none}
</style>

<!-- <script type="text/javascript">
function displaymessage()
{

alert("Your order has been created successfully!");

}
</script>-->

<apex:pageBlock title="Order edit" mode="edit">
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}"/>
<apex:commandButton value="Cancel" action="{!cancel}"/>

</apex:pageBlockButtons>
<apex:pageBlockSection title="Order Information" columns="2">
<apex:variable var="c" value="{!RT}" />


<apex:inputfield value="{!$CurrentPage.parameters.RT}"/>
<apex:inputField value="{!order.AccountId}" required="true"/>
<apex:inputField value="{!order.OpportunityId}"/>
<apex:inputField value="{!order.Equipment_Name__c}" required="true"/>
<apex:inputField value="{!order.PoDate}"/>
<apex:inputField value="{!order.PoNumber}"/>
<!-- <apex:inputField value="{!order.OrderNumber}"/> -->
<apex:inputField value="{!order.Type}"/>
<apex:inputField value="{!order.Order_Reason__c}"/>
<apex:inputField value="{!order.Order_Start_Date__c}" required="true"/>
<apex:inputField value="{!order.EffectiveDate}" label="Order End Date"/>
<apex:inputField value="{!order.Status}"/>
<apex:inputField value="{!order.Case__c}" required="true"/>
<apex:inputField value="{!order.Payment_Options__c}"/>
<apex:inputField value="{!order.Signature_Required__c}"/>
<apex:inputField value="{!order.Delivery_Block_Status__c}"/>
<apex:inputField value="{!order.TotalAmount}"/> 
</apex:pageblockSection>

<apex:pageblockSection title="Other Information" columns="2">
<apex:inputField value="{!order.ContractId}"/>
<apex:inputField value="{!order.CustomerAuthorizedById}"/>
<apex:inputField value="{!order.CustomerAuthorizedDate}"/>
<apex:inputfield value="{!order.Ship_To_Name__c}"/>
<apex:inputfield value="{!order.Shipping_Method__c}"/>
<apex:inputfield value="{!order.Shipping_Account_Number__c}"/>
<apex:inputField value="{!order.Description}"/>
</apex:pageblockSection>




</apex:pageBlock>

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


Regards,
Amita
Dutta SouravDutta Sourav
Hi Amita,
Where is the controller used in your VF Page?
First You need to use extension in <apex:page> tag.
<apex:page standardController="Order" extensions="OrderRedirectExtensionController" showHeader="true" >


Best regards,
Sourav
Amita TatarAmita Tatar
Hi Sourav,
i have done that but while loading the page it shows invalid record type id error
Dutta SouravDutta Sourav
Use with sharing keyword.
public with sharing class OrderRedirectExtensionController{

 
Amita TatarAmita Tatar
Validation Errors While Saving Record(s)
There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Record Type ID: id value of incorrect type: ". 

Click here to return to the previous page.


This is the error thrown
Dutta SouravDutta Sourav
Check the Validation rules in Order
ManojjenaManojjena
Hi Amita ,
Can you please check the debug log and what value you are getting in the log statement you put in the constructor .
 
Amita TatarAmita Tatar
Okay i will check that. 
I also want to add a pop up message in this code on selection of record from look up
Janet EpebinuJanet Epebinu
Hi,
I want you to check the constructor. You have already declared the property on Order and again instantiated it in the constructor. 
Instead of
Order orderObj = new Order();

 in the constructor, change it to
orderObj = new Order();

 This is the reason for the invalid record type id 
 
UmeshBetiUmeshBeti
@Amita Tatar
check this snippet try to modify according your requirement.
 
contactObject = null;
contactObject = (Contact)Contact.sObjectType.newSObject(RecordTypeId,true);
//you will get the Default values, only if you have set the default values, for each picklist field under each recordType.
System.debug('contactObject:'+contactObject.PicklistField__c);