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
AcMEGXAcMEGX 

Set Record Type programmatically via VisualForce

Hi All,

    Good day. Is there a way to set the record type of a record to be saved via VF? Thanks!
Best Answer chosen by Admin (Salesforce Developers) 
ShamSham

Before saving the record

yourobject.RecordTypeId = "Your recordType Id";


All Answers

ShamSham

Before saving the record

yourobject.RecordTypeId = "Your recordType Id";


This was selected as the best answer
AcMEGXAcMEGX
Thanks! I will try it out later this afternoon.
Wingsrul91Wingsrul91

I do not understand this solution.

 

How do you set the recordtype id via visualforce.

Here is my code:

 

<apex:page standardController="Case"> <apex:form > <apex:pageBlock title="Edit Case for {!$User.FirstName}"> <apex:pageMessages /> <apex:pageBlockButtons > <apex:commandButton value="Save" action="{!save}"/> </apex:pageBlockButtons> <apex:pageBlockSection > <apex:inputField value="{!case.subject}"/> <apex:inputField value="{!case.Quick_Ticket_Name__c}"/> <apex:inputField value="{!case.status}"/> <apex:inputfield value="{!case.Quick_Ticket_check__c}"/> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>

Where do I set the value of the record type? 

 

 

cignuscignus

Sham wrote:

Before saving the record

yourobject.RecordTypeId = "Your recordType Id";


 

I am doing the exact thing. I log the recordType value before saving and it is correct, but it is not changed after saving the record.

I was changing RT in apex controller class, then I moved it to a trigger, none of which solved my problem.