Skip to content

\<object>.delete

The \<object>.delete API deletes the records that are qualified for the criteria from the local database.

Note:
* The column names and values provided as key value pairs are case sensitive.

Volt MX Iris (JavaScript)

Signature

<VMXObj>.delete(options, onSuccessCallback, onFailureCallback)

Parameters

ParameterTypeDescriptionRequired
optionsJSONA dictionary containing primary Keys. The options parameter accepts a JSON that has the following options keys primaryKeys whereCondition whereConditionAsAString trackChanges markForUpload For detailed information, refer Options Keys. If the options parameter is null or empty, all the records are deleted.Yes
successCallbackFunctionThe function is invoked on successful deletion of a record(s).Yes
failureCallbackFunctionThe function is invoked on failure with the cause of failure as an argument.Yes

Options Keys

ParameterTypeDescriptionRequired
primaryKeysJSONSpecify the primary keys of the record to be deleted. The Key Name is primaryKeys and the Value is a dictionary of primary keys.No
whereConditionJSONSpecify the where condition for the delete query. The Key Name is whereCondition and the Values are column names and their respective values.No
whereConditionAsAStringStringSpecify the where condition for the delete query. The Key Name is whereConditionAsAString and the Value is a string. Note: For SPA/Desktop Web channels, each condition must have only comparison operator (=,!=,>,<,>=,<=). Multiple conditions can be clubbed using conjunctions(AND,OR).Values containing whitespaces are not supported.No
trackChangesBooleanIf the trackChanges key is set to False, the record level operations are not tracked. When the option is set to false, the CUD operations performed on a record are not synced(uploaded). The key is set to True, by default.No
markForUploadBooleanIf the markForUpload key is set to False, the record changes are not uploaded to the server. The key is set to True, by default.No

Return Type

void

Example

//------- delete all records -------
var category = new voltmx.sdk.VMXObj("CATEGORY");

function successCallback(response) {
    //response holds value true
}

function errorCallback(error) {
    voltmx.print("Delete failed with error: " + JSON.stringify(error));
}
category.delete(null, successCallback, errorCallback);

//--------delete a record using composite primary key --------
var category = new voltmx.sdk.VMXObj("CATEGORY");
var options = {};
var primaryKeys = {};
primaryKeys["CATEGORY_KEY1"] = "1234";
primaryKeys["CATEGORY_KEY2"] = "23";
options["primaryKeys"] = primaryKeys;

function successCallback(response) {
    //response holds the value true
}

function errorCallback(error) {
    voltmx.print("Delete failed with error: " + JSON.stringify(error));
}
category.delete(options, successCallback, errorCallback);

//------- delete by whereCondition-------
var category = new voltmx.sdk.VMXObj("CATEGORY");
var whereClause = {};
whereClause["Category_PN"] = 7;
var options = {};
options["whereCondition"] = whereClause;

function successCallback(response) {
    //response holds the value true
}

function errorCallback(error) {
    voltmx.print("Delete failed with error: " + JSON.stringify(error));
}
category.delete(options, successCallback, errorCallback);

//------- delete by whereConditionAsAString -------
var category = new voltmx.sdk.VMXObj("CATEGORY");
var options = {};
var whereClause = "Category_PN = '7'";
options["whereConditionAsAString"] = whereClause;

function successCallback(response) {
    //response holds the value true
}

function errorCallback(error) {
    voltmx.print("Delete failed with error: " + JSON.stringify(error));
}
category.delete(options, successCallback, errorCallback);

//------- delete using Disable change tracking flag – trackChanges ---------
var options = {
    "trackChanges": false
};
var VMXObject = new voltmx.sdk.VMXObj("CATEGORY");
VMXObject.delete(options, successCallback, failureCallback);

//------- delete using markForUpload flag --------- 
var options = {
    "markForUpload": false
};
var VMXObject = new voltmx.sdk.VMXObj("CATEGORY");
VMXObject.delete(options, successCallback, failureCallback);  

Android (Java)

Signature

void <VMXObj>.delete(HashMap<String, Object> options, final VMXCallback syncCallback) throws Exception

Parameters

ParameterTypeDescriptionRequired
optionsHashMap <String, Object>The options parameter accepts a HashMap that has the following options keys primaryKeys whereCondition whereConditionAsAString trackChanges markForUpload For detailed information, refer Options Keys. If the options parameter is null or empty, all the records are deleted.Yes
syncCallbackVMXCallbackTakes onSuccess and onFailure methods.Yes

Options Keys

KeysTypeDescriptionRequired
primaryKeysHashMap <String, Object>Specify the primary keys of the record to be deleted. The Key Name is primaryKeys and the Value is a hashmap of primary keys.No
whereConditionHashMap <String, Object>Specify the where condition for the delete query. The Key Name is whereCondition and the Value is a map containing column names and their respective values.No
whereConditionAsAStringStringSpecify the where condition for the select query. The Key Name whereConditionAsAString and the Value is a string. Note: For SPA/Desktop Web channels, each condition must have only comparison operator (=,!=,>,<,>=,<=). Multiple conditions can be clubbed using conjunctions(AND,OR).Values containing whitespaces are not supported.No
trackChangesBooleanIf you set the trackChanges key to False, the record level operations are not tracked. When the option is set to false, the CUD operations performed on a record are not synced (uploaded). The key is set to True, by default.No
markForUploadBooleanIf you set the markForUpload to False, the record changes are not uploaded to the server. The key is set to True, by default.No

Return Type

void

Example

//Delete record with a primary key 
VMXObj category = new VMXObj("CATEGORY");
HashMap < String, Object > primaryKeys = new HashMap < > ();
primaryKeys.put("CATEGORY_ID", "123");
HashMap < String, Object > options = new HashMap < > ();
options.put("primaryKeys", primaryKeys);
try {
    category.delete(options, new VMXCallback() {
        @Override
        public void onSuccess(Object object) {
            Log.d("Object Delete", "Object Delete Successful for category");
        }
        @Override
        public void onFailure(object error) {
            OfflineObjectsException e = (OfflineObjectsException) error;
            Log.e("Object Delete", "Object Delete Unsuccessful for category with Error :" + e.getMessage());
        }
    });
} catch (Exception e) {
    Log.e("Object Delete", "Failed to delete with exception: " + e.getMessage());
}
//Delete record with composite primary key 

HashMap < String, Object > primaryKeys = new HashMap < > ();
primaryKeys.put("CATEGORY_KEY1", "123");
primaryKeys.put("CATEGORY_KEY2", "124");
HashMap < String, Object > options = new HashMap < > ();
options.put("primaryKeys", primaryKeys);
try {
    category.delete(options, new VoltMXSyncCallback() {
        @Override
        public void onSuccess(Object object) {
            Log.d("Object Delete", "Object Delete Successful for category");
        }
        @Override
        public void onFailure(object error) {
            OfflineObjectsException e = (OfflineObjectsException) error;
            Log.e("Object Delete", "Object Delete Unsuccessful for category with Error :" + e.getMessage());
        }
    });
} catch (Exception e) {
    Log.e("Object Delete", "Object Delete Unsuccessful for category with Error :" + e.getMessage());
}

//Delete record using whereCondition 
VMXObj category = new VMXObj("CATEGORY");
HashMap < String, Object > whereClause = new HashMap < > ();
whereClause.put("CATEGORY_ID", "123");
HashMap < String, Object > options = new HashMap < > ();
options.put("whereCondition", whereClause);
try {
    category.delete(options, new VMXCallback() {
        @Override
        public void onSuccess(Object object) {
            Log.d("Object Delete", "Object Delete Successful for category");
        }
        @Override
        public void onFailure(object error) {
            OfflineObjectsException e = (OfflineObjectsException) error;
            Log.e("Object Delete", "Object Delete Unsuccessful for category with Error :" + e.getMessage());
        }
    });
} catch (Exception e) {
    Log.e("Object Delete", "Failed to delete with exception: " + e.getMessage());
}

//Delete record using whereConditionAsAString 
VMXObj category = new VMXObj("CATEGORY");
String whereClause = "CATEGORY_ID = '123'";
HashMap < String, Object > options = new HashMap < > ();
options.put("whereConditionAsAString", whereClause);
try {
    category.delete(options, new VMXCallback() {
        @Override
        public void onSuccess(Object object) {
            Log.d("Object Delete", "Object Delete Successful for category");
        }
        @Override
        public void onFailure(object error) {
            OfflineObjectsException e = (OfflineObjectsException) error;
            Log.e("Object Delete", "Object Delete Unsuccessful for category with Error :" + e.getMessage());
        }
    });
} catch (Exception e) {
    Log.e("Object Delete", "Failed to delete with exception: " + e.getMessage());
}

//Disable change tracking - trackChanges 
HashMap < String, Object > options = new HashMap < > ();
options.put(KSPublicConstants.TRACK_CHANGES, false);
sdkObjectSync.delete(options, new VMXCallback() {
    @Override
    public void onSuccess(Object object) {}
    @Override
    public void onFailure(object error) {}
});

//Mark for Upload 
HashMap < String, Object > options = new HashMap < > ();
options.put(KSPublicConstants.MARK_FOR_UPLOAD, false);
sdkObjectSync.delete(options, new VMXCallback() {
    {
        @Override
        public void onSuccess(Object object) {}
        @Override
        public void onFailure(object error) {}
    });  

iOS (Objective C)

Signature

void <object>.delete:(NSDictionary <NSString *, id> *)options   
onSuccess:(VMXSuccessCompletionHandler)onSuccess
onFailure:(VMXFailureCompletionHandler)onFailure

Parameters

ParameterTypeDescriptionRequired
optionsNSDictionaryThe options parameter accepts a NSDictionary that has the following options keys primaryKeys whereCondition whereConditionAsAString trackChanges markForUpload For detailed information, refer Options Keys. If the options parameter is null or empty, all the records are deleted.Yes
onSuccessVMXSuccessCompletionHandlerThe function is invoked on successful deletion of record(s).Yes
onFailureVMXFailureCompletionHandlerThe function is invoked on an error with the cause of failure as an argumentYes

Options Keys

KeysTypeDescriptionRequired
primaryKeysNSDictionary<NSString*, id>Specify the primary keys of the record to be deleted. The Key Name: primaryKeys and value is a dictionary of primary keys.No
whereConditionNSDictionary<NSString*, id>Dictionary of column names and their respective values according to which the records are to be deleted.No
whereConditionAsAStringNSStringSpecify the where condition for the delete query. Key Name: whereConditionAsAString and the value is a string. Note: For SPA/Desktop Web channels, each condition must have only comparison operator (=,!=,>,<,>=,<=). Multiple conditions can be clubbed using conjunctions(AND,OR). Values containing whitespaces are not supported.No
trackChangesBooleanIf you set the trackChanges key to False, the record level operations are not tracked. When the option is set to false, the CUD operations performed on a record are not synced (uploaded). The key is set to True, by default.No
markForUploadBoolean