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
HarmoineHarmoine 

RecordType

How do you create a standard object say 'Contact' record of a particular RecordType say 'InternalContact' from a VF page? When I create the contact using standard controller, the default Contact record gets created not the internalContact recordtype. How do we do this cast?

Best Answer chosen by Admin (Salesforce Developers) 
OzymandiasOzymandias

Alternatively, if you don't want to give your users a choice, you can use a SOQL statement in your controller to retrieve the Id of 'InternalContact' from the RecordType table, then set it as the value of Contact.RecordTypeId.

 

e.g.

RecordType contactRecType = [select Id from RecordType where Name='InternalContact'];
Contact newContact = new Contact(RecordTypeId=contactRecType.Id);

 

All Answers

srikeerthisrikeerthi

Hi

 

If your Saving record from VF page,then you can specify the Record Type of the Contact by using

<apex:inputfield>.Then you can select the Record type and then save the record.

 

 

Thanks

OzymandiasOzymandias

Alternatively, if you don't want to give your users a choice, you can use a SOQL statement in your controller to retrieve the Id of 'InternalContact' from the RecordType table, then set it as the value of Contact.RecordTypeId.

 

e.g.

RecordType contactRecType = [select Id from RecordType where Name='InternalContact'];
Contact newContact = new Contact(RecordTypeId=contactRecType.Id);

 

This was selected as the best answer
HarmoineHarmoine

Thank you so much!!  It worked!! I have been on it for hours. Thankyou!!!