Closed rakeshml closed 6 years ago
Can you share a code sample?
My suspicion is that this is a limitation with Salesforce's Metadata API, rather than anything directly under the control of this library. You can confirm for yourself by attempting the same change through the Salesforce workbench, and seeing if the same issue occurs.
Below is the code used from MetadataServiceExamples.
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]);
}
The problem seems to be the XML payload from the SOAP Callout is not changing the value of sharingModel for that object. However, if i manually edit the object file and change the sharingModel value and save, it is working. Need to figure out why the SOAP Callout is not changing value of sharingModel.
@rakeshml run your code from within the developer console exec anonymous window and observe the XML in the debug log that is being generated. Can you spot anything different from your manual edit approach?
Hey, I see you ended up getting an answer on StackExchange. Sorry for the delay, but it looks like it's now recognised by Salesforce as a Known Issue - https://success.salesforce.com/issues_view?Id=a1p3A0000018CP2
The workaround is to update the custom object using a metadata api deploy, rather than a CRUD based call.
I am trying to update the OWD using upsertObject method in MetadataServiceExamples class and it is not getting updated. However, there are no errors thrown.
I created the object with sharingModel as 'ReadWrite' and trying to update the sharing model to 'Private'. I can update the label, pluralLabel and other attributes but not the sharingModel.