Dynamic delete

Hi all, I want to dynamically delete certain object. I use the MxModelReflextion to identify my object. I Use the following code: String FullPathName = "domain.proxies." + NameAr[1]; Class<?> SelectedProxy = Class.forName(FullPathName); MendixObject DeleteMe = (IMendixObject)SelectedProxy.newInstance( ); Core.delete(getContext(), DeleteMe); The nameAr item is the actual entity name, i get a initialisationException can anyone explain why and how t fix it? Thanks in advance.
2 answers

Based on your code I'm not sure what you are trying to do. I don't think you shouldn't/can't initialize proxies that way.

There are several alternatives to dynamically delete objects. For example this one that we use. It removes objects based on a OQL query (which you can build dynamically).

    IDataTable table = Core.retrieveOQLDataTable(this.getContext(), this.oql);

    List<IDataRow> rows = (List<IDataRow>) table.getRows();

    ArrayList<IMendixIdentifier> ids = new ArrayList<IMendixIdentifier>();

    for(IDataRow row : rows){
        ids.add((IMendixIdentifier) row.getValue(this.getContext(), 0));

    Core.remove(this.getContext(), ids);

    return Long.valueOf(rows.size());

You question is vague, you want to delete a 'certain' object, but only specify the type of that object, using model reflection, so I guess you want to delete all objects of 'a certain type'?

Note that your class tries to just delete a new object that you just created, which is a bit pointless.

To delete all items of a certain type, use community commons:

XPath.create(getContext(), "MyModule.EntityName").deleteAll()