+ Start a Discussion
WEN JIEWEN JIE 

Insert data fail when Standard field “Name” is “Auto Number” type.

Hi,

 

I use rest api to do the CRUD with Salesforce data.

But when I do the insert data I met a problem.

My object's Standard Field Name "Name" 's Data Type is "Auto Number".  So I set a value like my auto-number style like "A0002", then I call the endpoint. But I see the following error:

 

Fail to create record on TestPackage11__TestWen__c. Unable to create/update fields: Name. Please check the security settings of this field and verify that it is read/write for your profile or permission set.

 

Then I change this Data Type as a "Text", the create operate can work successful.

 

So does anyone know how to insert a data when the object's name fields is the auto-number type?

 

Thank you!

Best Answer chosen by Admin (Salesforce Developers) 
SuperfellSuperfell

You're still passing name, remove name entirly from the request.

All Answers

ssssssssssssssss

If name is auto number , the field will get auto populated on inesert. Dont set any value for name. It will work.

WEN JIEWEN JIE

Hi,

 

Thanks for your answer.

I removed the value and try the insert again. But still see that error. 

Have a look with my code. I use Salesforce Integration Components in my Java project.(http://hst-salesforce.forge.onehippo.org/gettingstarted.html)

 

public static void createData(String object_name, String record_name) 
	throws SalesForceException, IOException{

    JSONObject json = JSONObject.fromObject("{ \"Name\": \"\" }");
    JSONObject jsonObject = (JSONObject) client.createRecord("/sobjects/"+object_name+"", json);
    System.out.println("Created object: " + jsonObject);
    String id = jsonObject.getString("id");
    System.out.println("Id : "+id);
}

 

SuperfellSuperfell

You're still passing name, remove name entirly from the request.

This was selected as the best answer
WEN JIEWEN JIE

Hi,

 

I remove the name, it works well.

Thank you!