<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 | 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
Examples
// Delete record with a primary key
VMXObj * _categories = [
[VMXObj alloc] initWithName: @"CATEGORY"
error: & error
];
NSMutableDictionary * options = [NSMutableDictionary new];
NSMutableDictionary * primaryKeys = [NSMutableDictionary new];
primaryKeys[@"CATEGORY_ID"] = @"112";
options[@"primaryKeys"] = primaryKeys;
[_categories delete: options
onSuccess: ^ (id object) {
NSLog(@"Deleted successfully");
}
onFailure: ^ (id object) {
OfflineObjectsError * error = (OfflineObjectsError) object;
NSLog(@"Delete record failed with error %@", [error.userInfo localizedDescription]);
}
];
// Delete record with composite primary key
VMXObj * _categories = [
[VMXObj alloc] initWithName: @"CATEGORY"
error: & error
];
NSMutableDictionary * recordToUpdate =
NSMutableDictionary * options = [NSMutableDictionary new];
NSMutableDictionary * primaryKeys = [NSMutableDictionary new];
primaryKeys[@"PRIMARY_KEY1"] = @"123";
primaryKeys[@"PRIMARY_KEY2"] = @"222";
options[@"primaryKeys"] = primaryKeys;
[_categories delete: options
onSuccess: ^ (id object) {
NSLog(@"Deleted successfully");
}
onFailure: ^ (id object) {
OfflineObjectsError * error = (OfflineObjectsError) object;
NSLog(@"Delete record failed with error %@", [error.userInfo localizedDescription]);
}
];
// Delete record using whereCondition
VMXObj * _categories = [
[VMXObj alloc] initWithName: @"CATEGORY"
error: & error
];
NSMutableDictionary * options = [NSMutableDictionary new];
NSMutableDictionary * whereClause = [NSMutableDictionary new];
whereClause[@"CATEGORY_ID"] = @"112";
options[@"whereCondition"] = whereClause;
[_categories delete: options
onSuccess: ^ (id object) {
NSLog(@"Deleted successfully");
}
onFailure: ^ (id object) {
OfflineObjectsError * error = (OfflineObjectsError) object;
NSLog(@"Delete record failed with error %@", [error.userInfo localizedDescription]);
}
];
// Delete record using whereConditionAsAString
VMXObj * _categories = [
[VMXObj alloc] initWithName: @"CATEGORY"
error: & error
];
NSMutableDictionary * options = [NSMutableDictionary new];
NSString * whereClause = @"CATEGORY_ID = '112'";
options[@"whereConditionAsAString"] = whereClause;
[_categories delete: options
onSuccess: ^ (id object) {
NSLog(@"Deleted successfully");
}
onFailure: ^ (id object) {
OfflineObjectsError * error = (OfflineObjectsError) object;
NSLog(@"Delete record failed with error %@", [error.userInfo localizedDescription]);
}
];
//Disable change tracking - trackChanges
NSDictionary < NSString * , id > * options = @ {
VMXCONSTANTS_TRACK_CHANGES_ UPDATES: @NO
};
[sdkObjectSync delete: options
onSuccess: ^ (id object) {}
onFailure: ^ (id object) {}
];
//Mark for Upload
NSDictionary < NSString * , id > * options = @ {
VMXCONSTANTS_MARK_FOR_ UPLOAD: @NO
};
[sdkObjectSync delete: options
onSuccess: ^ (id object) {}
onFailure: ^ (id object) {}
];
Note: Cascade Delete is enabled if the option is checked in VoltMX Foundry Console >> Object Services >> under configuring relationships in a data model. When this option is enabled, the child records are deleted recursively along with the parent record. This option is applicable for all platforms except for SPA/Desktop Web channels of Volt MX Iris.
Note:
- The trackChanges flag must be used consistently (either always true or always false) for all CUD operations on a record. You must not update the value of "change tracking" flag in between CUD operations on a record.
- When you set both markForUpload and trackChanges flags, an error is reported as these are mutually exclusive options.
- The change tracking option for Cascade Delete is also applicable for the child records.
- For Hierarchical Objects, you must provide a proper value for both parent and child record operations.
- The primaryKeys, whereCondition, and whereConditionAsAString are considered as the criteria to update a record. Only one criterion is considered at a time and the order is primaryKeys > whereCondition > whereConditionAsAString.
Note: To soft delete a column, mention the softdelete column name. Ensure all the tables have the same softdelete column name. For the offline object service with multiple objects, if the soft delete column is not common for all the objects, instead of using delete API, use the
<object>.update
API and set the softdelete field to true in the device database. For more information, refer to Offline Objects API Developer's Guide > <object>.update API.