Skip to content

<object>.deleteByPK

The <object>.deleteByPK API deletes an existing record from the local database for a given primary key.

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

Volt MX Iris (JavaScript)

Signature

<object>.deleteByPK(options, onSuccessCallback, onFailureCallback)

Parameters

ParameterTypeDescriptionRequired
optionsJSONA dictionary containing mandatory key primaryKey which contains the PK (column name and value). In case of a composite PK, the dictionary will contain multiple key-value pairs.Yes
onSuccessCallbackFunctionThe function is invoked on successful deletion of a record.Yes
onFailureCallbackFunctionThe function is invoked on an error with the cause of failure as an argument.Yes

Options Keys

KeysTypeDescriptionRequired
primaryKeysJSONSpecify the primary keys of the record to be deleted. Key Name: primaryKeys and value is a dictionary of primary keys.Yes
trackChangesJSONSet 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).
Note:
i) Supported for Windows from V8 SP4 Fix Pack 6 onwards.
ii) Supported for Mobile Web and Desktop Web channels from V8 SP4 Fix Pack 12 onwards.
No
markForUploadJSONSet the markForUpload to false, the record changes are not uploaded to the server.
Note:
i) Supported for Windows from V8 SP4 Fix Pack 6 onwards.
ii) Supported for Mobile Web and Desktop Web channels from V8 SP4 Fix Pack 12 onwards.
No

Return Type

void

Example

//Success callback
function onSuccess() {
    voltmx.print("record updated successfully");
}
//Failure callback
function onFailure(error) {
    voltmx.print(error.code);
}

//Sample to delete a record using PK
var categories = new voltmx.sdk.VMXObj("CATEGORY");
var primaryKeys = {};
primaryKeys["CATEGORY_ID"] = "1234";
var options = {};
options["primaryKeys"] = primaryKeys;
//Invoke the delete API
categories.deleteByPK(options, onSuccess, onFailure);


//Sample to delete a record using composite primary key
var categories = new voltmx.sdk.VMXObj("CATEGORY");
var primaryKeys = {};
primaryKeys["CATEGORY_KEY1"] = "1234";
primaryKeys["CATEGORY_KEY2"] = "23";
var options["primaryKeys"] = primaryKeys;
//Invoke the delete API to delete record having composite primary key(CATEGORY_KEY1 and CATEGORY_KEY2)
categories.deleteByPK(options, onSuccess, onFailure);

//Disable Change Tracking
var options = {
    "trackChanges": false
};
var VMXObject = new voltmx.sdk.VMXObj("CATEGORY");
VMXObject.deleteByPK(options, onSuccess, onFailure);

//Mark for Upload
var options = {
    "markForUpload": false
};
VMXObject.deleteByPK(options, onSuccess, onFailure);  

Android (Java)

Signature

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

Parameters

ParameterTypeDescriptionRequired
optionsHashMap<String, Object>key: primaryKeys. Value: HashMap<String, Object>: Pass a hashmap of primary keys and its value. HashMap containing PK (column name and value). In case of a composite PK, the dictionary will contain multiple key-value pairs.Yes
syncCallbackVMXCallbackTakes onSuccess and onFailure methods.Yes

Options Keys

KeysTypeDescriptionRequired
primaryKeysHashMapSpecify the primary keys of the record to be deleted. Key Name: primaryKeys and value is a hashmap of primary keys.Yes
trackChangesHashMapSet 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).No
markForUploadHashMapSet the markForUpload to false, the record changes are not uploaded to the server.No

Return Type

void

Examples

VMXObj category = new VMXObj("CATEGORY");
HashMap < String, Object > options = new HashMap < > ();
HashMap < String, Object > primaryKeys = new HashMap < > ();
primaryKeys.put("CATEGORY_ID", "123");
options.put("primaryKeys", key);

try 
    category.deleteByPK(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", "Object Delete Unsuccessful for category with Error :" + e.getMessage());
    e.printStackTrace();
}
//Disable change tracking
Hashmap < string, object > options = new HashMap < > ();
options.put(KSPublicConstants.TRACK_CHANGES, false);
sdkObjectSync.deleteByPK(options, new VMXCallback() {
    @Override
    public void onSuccess(Object object) {}
    @Override
    public void onFailure(object error) {}
});

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

iOS (Objective C)

Signature

void [<object> deleteByPK:(NSDictionary <NSString *, id> *)options                
onSuccess:(VMXSuccessCompletionHandler)onSuccess 
         onFailure:(VMXFailureCompletionHandler)onFailure];

Parameters

ParameterTypeDescriptionRequired
optionsNSDictionaryThe options parameter accepts a HashMap that has the following options keys primaryKeys trackChanges markForUpload For detailed information, refer Options Keys. If the options parameter is omitted, all the records will be deleted.Yes
onSuccessCallbackVMXSuccessCompletionHandlerThe function is invoked on successful deletion of a record.Yes
onFailureCallbackVMXFailureCompletionHandlerThe 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. Key Name: primaryKeys and value is a dictionary of primary keys.Yes
trackChangesNSDictionary<NSString*, id>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).No
markForUploadNSDictionary<NSString*, id>Set the markForUpload to false, the record changes are not uploaded to the server.No

Return Type

void

Example

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

NSDictionary * primaryKeys = @ {@
    "CATEGORY_ID": "1234"
};
NSDictionary * options = @ {@
    "primaryKeys": primaryKeys
};

[_categories deleteByPK: options onSuccess: ^ (id object) {
        //On Success block
        NSLog(@"Delete record succeded");

    }
    onFailure: ^ (id object) {
        OfflineObjectsError * error = (OfflineObjectsError) object;
        NSLog(@"Delete record Failed with error %@", [error.userInfo localizedDescription]);

    }
];

//Disable change tracking
NSDictionary < NSString * , id > * options = @ {
    VMXCONSTANTS_TRACK_CHANGES: @NO
};
[sdkObjectSync deleteByPK: options
    onSuccess: ^ (id object) {}
    onFailure: ^ (id object) {}
];

//Mark for Upload
NSDictionary < NSString * , id > * options = @ {
    VMXCONSTANTS_MARK_FOR_UPLOAD: @NO
};
[sdkObjectSync deleteByPK: options
    onSuccess: ^ (id object) {}
    onFailure: ^ (id object) {}
];  

Note:
  • Cascade Delete is enabled if the option is selected in VoltMX Foundry Console > Object Services > under configuring relationships in a data model. When this option is enabled, the child records will be deleted recursively along with the parent record.
  • Supported in iOS and Android platforms from V8 SP2 onwards.
  • Supported in Mobile and Desktop Web channels from V8 SP4 onwards.
  • 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.