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
John BrumbelowJohn Brumbelow 

HOWTO Create Lead object with REST api vs 400 error


Please help.
We are trying to use the REST api with the "Lead" object in SFDC. Attempts to create a record all fail with a 400 error. We have been using the REST api with custom objects with great success but the Lead object does not work.
We are our account has full sys-admin to the Lead object, and we can run the developer console and run SoQL queries like this:
select Name, Number_of_Vehicles__c, Online_Pages_Completed__c, Title from Lead
The JSON for the post to create a Lead object is as such:
{
"Name":"Test Name",
"Number_of_Vehicles__c":0.0,
"Online_Pages_Completed__c":1.0,
"Title":"Test"
}
The 400 error returned give no reason why this fails. And we've even tried just { "Name": "Test Name" } and still get the 400,
Someone else has posted about having 400 with Lead object as well here:
 - https://developer.salesforce.com/forums#!/feedtype=SINGLE_QUESTION_DETAIL&dc=APIs_and_Integration&criteria=OPENQUESTIONS&id=906F00000005Hz1IAE
 - https://success.salesforce.com/answers?id=90630000000461VAAQ
But no one answered their post.
Their JSON differed in that they tried "FirstName" and "LastName" instead of "Name", but we tried it as well as such:
{"FirstName":"Test","LastName":"Name"}
We still got the 400 error.
How can we trouble shoot the 400 and fix this issue?
John BrumbelowJohn Brumbelow
I have found the issue.
The Lead object to our business has had several hidden rules and validations.One can not see these rules/validations, even as admin, as they were applied through customaization, ON TOP OF, the Lead object. One would have to be full admin in SFDC, to hunt down the customizations to know about them.

As for how I found them. I used the SFDC workbench, here: https://workbench.developerforce.com/restExplorer.php
Which allows one to take the JSON, to try things out, and it gives a more detailed error message.

For more information on the SFDC workbench, refer to this article:
http://www.vinaychaturvedi.com/blog/learn-how-to-test-your-rest-apis-in-salesforce/

From the SFDC workbench, I tried my JSON, and got much more detailed information, and clearly saw the custom rules and validation in action, being to try JSON, see the more detailed error, and ultimately get the correct JSON vs the custom rules/validations.

I was then able to go to our admin teams, with the fields in question, and from it, learn more about the customized rules and validations.
As for why I say "rules" and "validations". There were rules, to concatenate two fields, to make another, and add a space between the two fields. And there was a validation, that made a plan/ordinary built-in-field, be required (not empty).

Hope this helps others.