Can OWD be imported/exported as metadata?

1.7K    Asked by bhagwatidubey in Salesforce , Asked on Jul 10, 2021

 I'm currently trying to create a scratch org which reflects our ludicrously complicated production org which contains hundreds of Roles.

Upon deploying most of these, I get errors like:

Error src/roles/WhateverUser.role WMSportCustomerUser field integrity exception: unknown (Opportunity access level below organization default) I guess this means I need to correctly configure the OWD before these roles can be deployed. Is there any way to do this using metadata (preferably "mdapi" since we aren't ready to move to "source" yet)? Don’t know how to import OWD as metadata?

Answered by Behailu

Yes. Each object has two fields, "sharing model" and "externalSharingModel". You can import and export these values between orgs. You'll find this setting in the CustomObject metadata. I personally use this method to set up the sharing model for standard and custom objects. There's some weird bugs around it sometimes, so some manual setup may still yet be required, but it mostly works okay. ... Read

Note: OWD stands for Organization-Wide Default (OWD). The Organization-Wide Default settings are the feature in Salesforce settings that allow you to specify that what all records can be accessed by which user is registered on the instance and also in which mode.



Your Answer

Answer (1)

Yes, Organization-Wide Defaults (OWD) settings can be imported and exported as metadata in Salesforce. OWD settings are part of the security settings that can be managed through the Metadata API, which allows you to deploy and retrieve metadata components.

Exporting OWD as Metadata

To export OWD settings, you need to retrieve the relevant metadata using the Salesforce Metadata API. The OWD settings are included in the settings section of the metadata, specifically within the SharingSettings metadata type.

Steps to Export OWD:

1. Create a Package.xml File:

This file specifies the metadata components to retrieve. For OWD, you need to include the SharingSettings metadata type.



   

        *

        SharingSettings

   

    56.0

Retrieve Metadata:



Use a tool like Salesforce CLI (sfdx), ANT Migration Tool, or Workbench to retrieve the metadata defined in the package.xml.

Using Salesforce CLI:


4 Months

Interviews

Parent Categories