I am trying to alter Organization-Wide Defaults (OWD) via apex using https://github.com/financialforcedev/apex-mdapi (Apex Wrapper Salesforce Metadata API) tool.
I can create custom object with attribute 'sharingModel' set to 'Read' and it works fine. But when I try to update 'sharingModel' set to 'ReadWrite', it does not update to 'ReadWrite'. However, there is no error thrown and all other fields are updated except 'sharingModel'. Any help would be helpful.
Thanks
Adding code: Code used from MetadataServiceExamples class.
This is when creating an object with sharingModel as "ReadWrite"
public static void createObject() {
MetadataService.MetadataPort service = createService();
MetadataService.CustomObject customObject = new MetadataService.CustomObject();
customObject.fullName = 'Test__c';
customObject.label = 'Test';
customObject.pluralLabel = 'Tests';
customObject.nameField = new MetadataService.CustomField();
customObject.nameField.type_x = 'Text';
customObject.nameField.label = 'Test Record';
customObject.deploymentStatus = 'Deployed';
customObject.sharingModel = 'ReadWrite';
List<MetadataService.SaveResult> results = service.createMetadata( new MetadataService.Metadata[] { customObject });
handleSaveResults(results[0]);
}
This is when updating the same object with sharingModel as "Private"
public static void upsertObject() {
MetadataService.MetadataPort service = createService();
MetadataService.CustomObject customObject = new MetadataService.CustomObject();
customObject.fullName = 'Test__c';
customObject.label = 'Test';
customObject.pluralLabel = 'Tests Upsert';
customObject.nameField = new MetadataService.CustomField();
customObject.nameField.type_x = 'Text';
customObject.nameField.label = 'Test Record Upsert';
customObject.deploymentStatus = 'Deployed';
customObject.sharingModel = 'Private';
List<MetadataService.UpsertResult> results = service.upsertMetadata( new MetadataService.Metadata[] { customObject });
handleUpsertResults(results[0]);
}