* @param mconn ForceMangedConnection
* @throws Exception Exception
*/
public static void cleanSchema(ForceManagedConnection mconn) throws Exception {
PartnerConnection pc = (PartnerConnection) mconn.getConnection();
ForceSchemaWriter writer = new ForceSchemaWriter(new SchemaDeleteProperty(true, true));
DescribeGlobalResult objs = pc.describeGlobal();
for (DescribeGlobalSObjectResult s : objs.getSobjects()) {
CustomObject co = new CustomObject();
co.setFullName(s.getName());
DescribeSObjectResult sobject = pc.describeSObject(s.getName());
Field[] fields = sobject.getFields();
List<CustomField> customFields = new ArrayList<CustomField>();
for (Field f : fields) {
if (f.isCustom()) {
CustomField cf = new CustomField();
cf.setFullName(f.getName());
if (!s.isCustom()) {
if (!customFieldsToKeep.contains((s.getName() + "." + f.getName()).toLowerCase())) {
writer.addCustomField(co, cf);
}
} else {
writer.addCustomField(co, cf);
customFields.add(cf);
}
}
}
if (customFields.size() > 0) {
co.setFields(customFields.toArray(new CustomField[customFields.size()]));
}
if (s.isCustom()) {
writer.addCustomObject(co, true);
}
}
writer.write(mconn);
}