+ 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