+ Start a Discussion
yervandyyervandy 

Record Types in Visualforce

I am trying to build a Visualforce page for submitting a new Case for one specific record type. I want the user to bypass picking a Record Type. When they click on a link, it will take them to this visualforce page, and I'd like my picklists in this page to display values compatible with a Record Type. Do I have to create a custom controller to handle the Record Type?

Best Answer chosen by Admin (Salesforce Developers) 
r1985r1985

Hi,

 

For this u can create either standard or custom controller and preset the record type. Salesforce has standard features for presetting the record type.

 

public class Caserecset

{

public Case c{get;set;}

public Caserecset()

{

c=new Case();

c.recordtypeid=urid;

}

}

 

Use this as a reference.

 

Thanks,

MVP

 

All Answers

r1985r1985

Hi,

 

For this u can create either standard or custom controller and preset the record type. Salesforce has standard features for presetting the record type.

 

public class Caserecset

{

public Case c{get;set;}

public Caserecset()

{

c=new Case();

c.recordtypeid=urid;

}

}

 

Use this as a reference.

 

Thanks,

MVP

 

This was selected as the best answer
Darshan FarswanDarshan Farswan

I have read about this thing earlier. Picklist can be made dependent on the Recordtype only for Standard Pages with the help of Page Layouts. It cannot be done for a Visualforce Page.

 

Please go through this article as well....

 

http://boards.developerforce.com/t5/Visualforce-Development/Dynamic-Picklist-values-based-on-Record-Type-in-VF/td-p/107542

 

 

r1985r1985

Hi Darshan,

 

We have already implemented this in our project and it is possible. Kindly go through the 'Overriding Buttons, Links, and Tabs with Visualforce' in VF Developer guide.

 

For ur reference ill give my vf page format.

 

<apex:page standardController="Name" extensions="extn">
   <apex:form >
   <apex:pageBlock >
       <apex:pageBlockSection title="Title" columns="1">
            <apex:inputField value="{!objname.picklistfield}"/>
            <apex:inputField value="{!objname.picklistfield}"/>
       </apex:pageBlockSection>
       <center><apex:commandButton value="Continue" action="{!save}" />   </center>
       </apex:pageBlock>
    </apex:form>
</apex:page>

 

In the extn class, set the recordtype and the picklist will change dynamically.

 

If u want further help, let me know.

 

Thanks,

MVP

Darshan FarswanDarshan Farswan

Hi r1985

 

I did as you said, i presetted that recordTypeId in the constructor, but that didn't helped me in anything. The picklist still shows all the values. Although the RecordtypeId is correct the correct ID.

 

Here is my code

 

public class atest{
    public Opportunity opp{get;set;}
    public atest(ApexPages.StandardController controller)
    {
        opp = (Opportunity)controller.getRecord();
        opp.recordtypeid='012900000003DdU';
    }
}

 

 

<apex:page standardController="Opportunity" extensions="atest">
   <apex:form>
   <apex:pageBlock >
       <apex:pageBlockSection title="NOT RIGHT" columns="1">
            <apex:inputField value="{!opp.DeliveryInstallationStatus__c}"/>
            <apex:outputLabel value="{!opp.recordtypeid}"/>
       </apex:pageBlockSection>
       <center><apex:commandButton value="Continue" action="{!save}" />   </center>
       </apex:pageBlock>
    </apex:form>
</apex:page>

 

 

 

012900000003DdU RecordID that has only two values for DeliveryInstallationStatus__c field.

 

Suggest where I am going wrong.

 

Darshan FarswanDarshan Farswan

Hii

 

Hey I have fixed that issue of mine. I was doing the same in Version 18.0. After changing the version to 22.0 it ran smoothly.

So i guess dynamic picklist for a visualforce page can be generated by preseting the RecordtypeId in the constructor.

yervandyyervandy

Thanks guys. I will try that out.