JavaScript API 4.11 Sample Code

JavaScript API Update FeatureLayer using applyEdits()


Note: Support for 3D on mobile devices may vary, view the system requirements for more information.

This sample demonstrates how to use FeatureLayer.applyEdits() to create new features, update attributes of existing features or delete existing features. This sample uses the FeatureTemplates widget to display templates from the editable feature layer. The widget listens for an end user to select a specific template in the widget. Its select event is fired and the resulting template information is returned. This is used in creating new features.

In addition to the FeatureTemplates widget, this sample also uses the FeatureForm widget to update attributes of new or existing features.

In this sample, the applyEdits function is called when a user either:

  • Clicks to create a new feature.
  • Selects a feature on the view and updates its attributes.
  • Selects a feature on the view and deletes it.
// Call FeatureLayer.applyEdits() with specified params.
function applyEdits(params) { = "none"; = "none";

    .then(function(editsResult) {
      // Get the objectId of the newly added feature.
      // Call selectFeature function to highlight the new feature.
      if (editsResult.addFeatureResults.length > 0) {
        const objectId = editsResult.addFeatureResults[0].objectId;
    .catch(function(error) {
      console.error("[ applyEdits ] FAILURE: ", error.code,, error.message);
      console.log("error = ", error);

FeatureLayer.applyEdits() resolves to an object containing edit results. If the edit failed, the edit result includes an error.

Sample search results