Hello,
I'm trying to add a feature to FeatureService but I have error at addFeature function.
Hi there,
The expectation would be that the OBJECTID is generated when you perform the add feature call since ObjectIds are determined by the feature service.
Does your service definitely have the OBJECTID configured correctly? It should have the Field name OBJECTID (which from the exception you're getting I'd expect it will) and it should be of type "ObjectId".
Another thought - I take it since you are successfully creating the feature that you are awaiting a successful load of the service feature table before attempting any feature management?
A confidence check could be to play around with the data from our "Manage Features" sample. While the sample uses the service geodatabase approach, I was able to use your workflow above and substitute in the service URL from that dataset - and amend the attributes per the sample - and successfully add features.
Demo Service: https://sampleserver6.arcgisonline.com/arcgis/rest/services/DamageAssessment/FeatureServer/0
Also unrelated but just an FYI - in your "// Check if the edit was successful" block - watch out for your null safety there, I think you need to ensure you're checking in all cases that editResults.isNotEmpty before accessing editResults.first.
I hope this helps.