\<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
Parameter | Type | Description | Required |
options | JSON | A 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 |
successCallback | Function | The function is invoked on successful deletion of a record(s). | Yes |
failureCallback | Function | The function is invoked on failure with the cause of failure as an argument. | Yes |
Options Keys
Parameter | Type | Description | Required |
primaryKeys | JSON | Specify the primary keys of the record to be deleted. The Key Name is primaryKeys and the Value is a dictionary of primary keys. | No |
whereCondition | JSON | Specify the where condition for the delete query. The Key Name is whereCondition and the Values are column names and their respective values. | No |
whereConditionAsAString | String | Specify 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 |
trackChanges | Boolean | If 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 |
markForUpload | Boolean | If 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
Parameter | Type | Description | Required |
options | HashMap <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 |
syncCallback | VMXCallback | Takes onSuccess and onFailure methods. | Yes |
Options Keys
Keys | Type | Description | Required |
primaryKeys | HashMap <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 |
whereCondition | HashMap <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 |
whereConditionAsAString | String | Specify 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 |
trackChanges | Boolean | If 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 |
markForUpload | Boolean | If 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
Parameter | Type | Description | Required |
options | NSDictionary | The 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 |
onSuccess | VMXSuccessCompletionHandler | The function is invoked on successful deletion of record(s). | Yes |
onFailure | VMXFailureCompletionHandler | The function is invoked on an error with the cause of failure as an argument | Yes |
Options Keys
Keys | Type | Description | Required |
primaryKeys | NSDictionary<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 |
whereCondition | NSDictionary<NSString*, id> | Dictionary of column names and their respective values according to which the records are to be deleted. | No |
whereConditionAsAString | NSString | Specify 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 |
trackChanges | Boolean | If 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 |
markForUpload | Boolean | |