Saving Data Objects

Top  Previous  Next

The API to save an object can be used for two separate scenarios: if an object has been previously saved, it is updated in the data store, otherwise it is saved (created). The save operation checks if the object has objectId assigned by the server. in that case, the object is updated, otherwise it is created in the Backendless data store. In case when there is no table for the persisted object, Backendless creates one and maps table's columns to the object's properties.

The objectId property is automatically assigned to all persisted objects when they are initially saved. See the Data Object section for details on objectId.



Backendless.PersistenceService.of( E ).save( entity:E, responder:IResponder )


E- ActionScript class of the data object to save.
entity- ActionScript object to persist, must be of type E.
responder- An instance of mx.rpc.IResponder which receives the callbacks when the function receives a response or an error from the server.


Consider the following class:

package com.sample
  public class Contact
    public var objectId:String;
    public var name:String;
    public var age:int;
    public var phone:String;
    public var title:String;

The following code saves an instance of Contact in Backendless:

// the following line is needed only for pure AS projects

Backendless.initApp( APP_ID, SECRET_KEY, "v1" );

var contact:Contact = new Contact();
contact.age = 33; = "James Bond"; = "5551212";
contact.title = "Chief Spying Officer";

var responder:IResponder = new Responder(
  function( evt:ResultEvent ):void
    var savedContact:Contact = evt.result as Contact;
    trace( "contact saved. ObjectId - " + savedContact.objectId );
  function( evt:FaultEvent ):void
    trace( "Error saving contact - " + evt.fault.faultDetail );

Backendless.PersistenceService.of( Contact ).save( contact, responder );



Please let us know how we can improve the documentation by leaving a comment. All technical questions should be posted to the Backendless Support forum. We do not respond to the technical questions on the documentation pages.: