Skip to content

\<object>.rollback

The \<object>.rollback function rolls back all changes of an object in a device's database to its previous sync state or a specific record supplied through the primaryKeyValueMap parameter.

Volt MX Iris (JavaScript)

Signature

<VMXObj>.rollback(primaryKeyValueMap, successCallback, failureCallback)

Parameters

ParameterTypeDescriptionRequired
primaryKeyValueMapJSONIf you want to rollback the changes of a particular record in the object, provide primaryKeyValueMap. Otherwise, you can provide null or empty JSON.Yes
successCallbackFunctionThe function is invoked on successful rollback.Yes
failureCallbackFunctionThe function is invoked on an error with the cause of failure as an argument upon Rollback failure.Yes

Return Type

void

Example

function successCallback() {
    voltmx.print("Object rollback successful: ");
}

function failureCallback(error) {
    voltmx.print("Object rollback failed: " + error.code);
}

var categories = new voltmx.sdk.VMXObj("CATEGORY");
var primaryKeyValueMap = {};
primaryKeyValueMap["CATEGORY_ID"] = 123;

// Rollback a specific record
categories.rollback(primaryKeyValueMap, successCallback, failureCallback);

// Rollback entire object
categories.rollback(null, successCallback, failureCallback);

Android (Java)

Signature

<VMXObj>.rollback(final HashMap<String, Object> primaryKeyValueMap, final VMXCallback callback)

Parameters

ParameterTypeDescriptionRequired
primaryKeyValueMapHashMap<String, Object>If you want to rollback the changes of a particular record in the object, provide primaryKeyValueMap. Otherwise, you can provide null or empty JSON.Yes
callbackVMXCallbackApplication implements onSuccess and onFailure methods of VMXCallback interface.Yes

Return Type

void

Example

VMXObj category = new VMXObj("CATEGORY");

//Rollback entire object
category.rollback(null, new VMXCallback() {
    @Override
    public void onSuccess(Object object) {
        Log.d("Object Rollback", "Object Rollback Successful for category");
    }
    @Override
    public void onFailure(object error) {
        OfflineObjectsException e = (OfflineObjectsException) error;
        Log.d("Object Rollback", "Object Rollback unsuccessful for category with Error :" + e.getMessage());
    }
});

//Rollback a record using primary key(s)
HashMap < String, Object > primaryKeyValueMap = new HashMap < String, Object > ();

primaryKeyValueMap.put("CATEGORY_ID", 123);

// Rollback a specific record
category.rollback(primaryKeyValueMap, new VMXCallback() {
    @Override
    public void onSuccess(Object object) {
        Log.d("Object Rollback", "Object Rollback Successful for category");
    }
    @Override
    public void onFailure(object error) {
        OfflineObjectsException e = (OfflineObjectsException) error;
        Log.e("Object Rollback", "Object Rollback unsuccessful for category with Error :" + e.getMessage());
    }
});

iOS (Objective C)

Signature

void <VMXObj> rollback:(NSDictionary <NSString *, id> *)primaryKeyValueMap 
                    onSuccess:(VMXSuccessCompletionHandler)onSuccess 
                    onFailure:(VMXFailureCompletionHandler)onFailure

Parameters

ParameterTypeDescriptionRequired
primaryKeyValueMapNSDictionary<NSString*, id>If you want to rollback the changes of a particular record in the object, provide primaryKeyValueMap. Otherwise, you can provide null or empty JSON.Yes
onSuccessVMXSuccessCompletionHandlerThe method called after a successful rollback.Yes
onFailureVMXFailureCompletionHandlerThe method called on Rollback failure.Yes

Return Type

void

Examples

NSError * error = nil;
VMXObj * _categories = [
    [VMXObj alloc] initWithName: @"CATEGORY"
    error: & error
];

// Rollback entire object
[_categories rollback: @{}
    onSuccess: ^ (id response) {
        NSLog(@"Rollback successful for Categories Object!");
    }
    onFailure: ^ (id object) {
        OfflineObjectsError * error = (OfflineObjectsError) object;
        NSLog(@"Error: Rollback unsuccessful because of error:%@", [error.userInfo localizedDescription]);
    }
];

// Rollback a record using primary key
NSDictionary < NSString * , id > * primaryKeyValueMap = @ {@
    "CATEGORY_ID": @123
};
[_categories rollback: primaryKeyValueMap
    onSuccess: ^ (id response) {
        NSLog(@"Rollback successful for Categories Object!");
    }
    onFailure: ^ (id object) {
        OfflineObjectsError * error = (OfflineObjectsError) object;
        NSLog(@"Error: Rollback unsuccessful because of error:%@", [error.userInfo localizedDescription]);
    }
];

Note: Rollback of records with relationships should be done with care. Otherwise, client database may get into the inconsistent case. For example, perform rollback on the child object before performing rollback on the parent.