Skip to content

Saving Single Object

Backendless.Data.of( "TABLE-NAME" ).save( { propertyA:"", propertyB:""} )
 .then( function( savedObject ) {
  })
 .catch( function( error ) {
  });
function DataTypeX() {
  this.propertyA = "";
  this.propertyB = "";
}
Backendless.Data.of( DataTypeX ).save( new DataTypeX() )
 .then( function( savedObject ) {
  })
 .catch( function( error ) {
  });

where:

Argument                Description
DataTypeX function/class identifying the table where the object will be stored. Instances of the class will be saved in the table.
"TABLE-NAME" name of the table where the object will be stored.

Return Value

Returns the saved object with the objectId property assigned by Backendless

Example

var contact = {
    name:"Jack Daniels",
    age:147,
    phone:"777-777-777",
    title:"Favorites"
}

Backendless.Data.of( "Contact" ).save( contact )
  .then( function( savedObject ) {
      console.log( "new Contact instance has been saved" );
    })
  .catch( function( error ) {
      console.log( "an error has occurred " + error.message );
    });
Consider the following class:
function Contact(args) {
    args = args || {};
    this.name = args.name || "";
    this.age = args.age || "";
    this.phone = args.phone || "";
    this.title = args.title || "";
}
The following code saves a new instance of the Contact class:
// do not forget to initialize the app with Backendless.initApp( appId, jsAPIKey );

var contactObject = new Contact( {
    name: "James Bond",
    age: 45,
    phone: "1-800-JAMESBOND",
    title: "chief spying officer"
});

Backendless.Data.of( Contact ).save( contact )
  .then( function( savedObject ) {
      console.log( "new Contact instance has been saved" );
    })
  .catch( function( error ) {
      console.log( "an error has occurred " + error.message );
    });