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
yudyud 

How do I set the Record Type of a new sObject

Hi

 

I create new Opporunity (by code) and want to set it's Record Type. 

How do I do it?

 

Yitzchak

Best Answer chosen by Admin (Salesforce Developers) 
hisrinuhisrinu

You can make the record type as below.

 

Opportunity opp = new Opportunity(recordtypeid = 'write your id here', name='name');

and mention the required fields then

insert opp;

All Answers

hisrinuhisrinu

You can make the record type as below.

 

Opportunity opp = new Opportunity(recordtypeid = 'write your id here', name='name');

and mention the required fields then

insert opp;

This was selected as the best answer
yudyud
Thanks