+ Start a Discussion
Matthew PantonMatthew Panton 

How can I set the RecordTypeId when creating a Lead through the REST API?

I'm able to create a new Lead through the API but unable to set the RecordTypeId. Even if I set the RecordTypeId in the request, and the request succeeds it will always fallback to the default Record Type.

I have checked the accessability level of the RecordTypeId field and it is editable by all.

Does anyone know where I'm going wrong?
Can your share the code that you are using? Any field differences in the record types?
Matthew PantonMatthew Panton
I'm using a Laravel package to submit the request https://github.com/omniphx/forrest
Forrest::sobjects('Lead', ['method' => 'post', 'body' => [
	'Lead_Type__c' => !empty($data['lead_type']) ? $data['lead_type'] : null,
	'RecordTypeId' => '0120Y000000ZAA7QAO',
	'FirstName'    => $name['firstName'],
	'LastName'     => $name['lastName'],
	'Company'      => (!empty($data['organisation']) && $data['organisation'] !== 'N/A') ? $data['organisation'] : null,
	'Phone'        => $isMobile ? null : $phone,
	'MobilePhone'  => $isMobile ? $phone : null,
	'Email'        => $data['email'],
	'Website'      => url()->previous(),
	'Post_Code__c' => $this->getCounty($data['postcode']),
	'Comments__c'  => $comments,
	'LeadSource'   => 'Website Enquiry',
	'Date_Lead_Generated__c' => Date('Y-m-d'),
	'Privacy_Policy_Disclaimer__c' => true,
There is nothing wrong with the request that I'm submitting because it is not throwing any exceptions and is showing a new Lead in Salesforce, it just doesn't have the correct RecordTypeId.
Did you try the 15 digit Id?
Matthew PantonMatthew Panton
How would I find the 15 digit ID please?
0120Y000000ZAA7 this is the 15 digit ID
The last 3 digits are appended can you check with this ID? 
Matthew PantonMatthew Panton
I just tried with that 15 digit ID, the request was accepted fine and a new Lead was created however the RecordTypeId was set as 0120Y000000ZAA6QAO which is the default Record Type. 
Hi Mathew,

Can you export one record from the 0120Y000000ZAA7 record type along with the record type ID to check whether the ID is correct, your code seems correct to me just perform an export and verify the record type ID
Hi Mathew,

For the integration purposes you  might have created a dummy user with some profile considering this is a REST API, for example we create an Integration user for any sort of integration and assign a profile to this user, can you check whether that profile has access to this record type, if not please provide the same and verify.
Matthew PantonMatthew Panton
The API user that is making the request is assigned to the System Administrator profile which has access to this record type.
Matthew PantonMatthew Panton
I've half solved this now. 
Instead of setting the RecordTypeId when creating the lead, I'm making a second API call to update the RecordTypeId once the Lead has been created.
It's far from ideal but at least it works.
Thaks for your help Deepesh.
Nice one Mathew Missed out on that but 2 API calls for one lead can create issues
Matthew PantonMatthew Panton
I know it could have issues but I had to at lead get it working.

I'm having a similar issue again with OwnerId this time, but I can't even change the value in a PATCH request now.

I've tried running a request in the Salesforce Workbench (https://workbench.developerforce.com/restExplorer.php) with no exceptions being thrown however the OwnerId of the lead still isn't updated.
Alicia GayoutAlicia Gayout

Hi, here we have exactly the same problem, submitting the request from our NodeJS API.

Both also for RecordTypeId and OwnerId.

We want to create a given RecordType and add its 15-digit Id, and the API indeed checks on creation that the right values for this RecordType are sent altogether. But then the RecordType is set back to default...

Rahul Nagardalekar 21Rahul Nagardalekar 21
Hey Matthew,

Regarding creating a lead, update the lead conversion settings to push the correct lead. Make sure you select "Keep the existing record type" when manually created records.

User-added image
Stamen Nikolov 4Stamen Nikolov 4
Hi, is this solved or not? To me it sounds like there is a default record type selected for leads, have you checked this?
Salesforce Analytics 3Salesforce Analytics 3

Hi, we have faced the same problem and a solution was: 

send record type ID in the 15-digit format as 

'recordType' => self::LEAD_RECORD,

please, note that the main difference is in the key name - recordType instead of RecordTypeId
Andrew Nguyen 61Andrew Nguyen 61
This may be old, but for whoever looking, I was able to resolve this by setting the following header to not auto-assign the record which will set default record type and name.

Set the following header: 

Sforce-Auto-Assign: False