0

I recently started a project, which has a OLD Sandbox, where development was going on, now we need to start using GIT, which is causing huge problem, because we are not able to pull FieldPermissions & ClassAccess for Profiles means we will not be able to set CI/CD.

Do any one have solution how we can enable SourceTracking on existing Sandboxes once it is enabled in Prod.

2
  • How is no source tracking blocking you? You can retrieve FieldPermissions and ClassAccess as long as you retrieve Apex Class and Custom Objects along with your profiles in any retrieval request. Commented Feb 5, 2022 at 17:29
  • @KrisGoncalves I can retrieve with Profile, but my need is to push all these to GIT, and it is not always ideal to pull Classes, Fields, Objects everytime. Also in my Sandbox, it was not seeming possible and I was just getting the permissions. I enabled SourceTracking created another sandbox, and pushed everything from SB 1 to SB2, and now things are working as expected. Commented Feb 7, 2022 at 5:37

1 Answer 1

3
+50

Do any one have solution how we can enable SourceTracking on existing Sandboxes once it is enabled in Prod.

No. You have to refresh the sandbox from production (which you've enabled it in) to have SourceTracking in the sandbox. It's highlighted in Enable Source Tracking in Sandboxes

To enable Source Tracking in Sandboxes:

  1. Log in to your production org.
  2. From Setup, in the Quick Find Box, enter Dev Hub and select Dev Hub.

If you don't see Dev Hub in the Setup menu, make sure that your org is one of the supported editions. Dev Hub is available in Enterprise, Performance, and Unlimited Editions.

  1. Select Enable Source Tracking in Developer and Developer Pro Sandboxes.

After you enable this setting, Developer and Developer Pro Sandboxes that are created or refreshed have Source Tracking enabled. For information about how to use source tracking in sandboxes, see the Salesforce DX Developer Guide.

In terms of profiles, there's nothing stopping you from pulling the relevant metadata in a sandbox even if it's less efficient. Profiles return information only when your retrieval/request contains the related metadata

The content of a profile returned by Metadata API depends on the content requested in the RetrieveRequest message. For example, profiles only include field-level security for fields included in custom objects returned in the same RetrieveRequest as the profiles.

As such, to get FieldPermissions and ClassAccess, you will need to make sure you're retrieving all your Objects and Apex Classes when retrieving

sfdx force:source:retrieve -m "CustomObject,ApexClass,Profile"

However, the big caveat is that the above will pull all custom objects/fields, but not the standard objects. Noted in sample package.xml manifest files,

Note how you work with the standard Account object by specifying it as a member of a CustomObject type. However, you can’t use an asterisk wildcard to work with all standard objects; each standard object must be specified by name.

As such, you'll have to specify each standard object as a member of a CustomObject type as well as the wildcard for all custom objects.

sfdx force:source:retrieve -m CustomObject:Account,Contact,....

Since the list will be long, it's easier to create a package.xml to reference in your command

sfdx force:source:retrieve -x path/to/package.xml

Below is a list from my developer org and may not contain all the ones you may have:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
  <types>
    <members>*</members>
    <members>Account</members>
    <members>AccountBrand</members>
    <members>AccountContactRole</members>
    <members>AccountTeamMember</members>
    <members>ActiveScratchOrg</members>
    <members>Activity</members>
    <members>AlternativePaymentMethod</members>
    <members>Asset</members>
    <members>AssetRelationship</members>
    <members>AssistantProgress</members>
    <members>AuthorizationForm</members>
    <members>AuthorizationFormConsent</members>
    <members>AuthorizationFormDataUse</members>
    <members>AuthorizationFormText</members>
    <members>Campaign</members>
    <members>CardPaymentMethod</members>
    <members>Case</members>
    <members>ChannelProgram</members>
    <members>ChannelProgramLevel</members>
    <members>ChannelProgramMember</members>
    <members>CommSubscription</members>
    <members>CommSubscriptionChannelType</members>
    <members>CommSubscriptionConsent</members>
    <members>CommSubscriptionTiming</members>
    <members>Contact</members>
    <members>ContactPointAddress</members>
    <members>ContactPointConsent</members>
    <members>ContactPointEmail</members>
    <members>ContactPointPhone</members>
    <members>ContactPointTypeConsent</members>
    <members>ContactRequest</members>
    <members>Contract</members>
    <members>DataUseLegalBasis</members>
    <members>DataUsePurpose</members>
    <members>DelegatedAccount</members>
    <members>DigitalWallet</members>
    <members>DuplicateRecordItem</members>
    <members>DuplicateRecordSet</members>
    <members>EngagementChannelType</members>
    <members>Event</members>
    <members>ExchangeUserMapping</members>
    <members>ExpressionFilter</members>
    <members>ExpressionFilterCriteria</members>
    <members>Idea</members>
    <members>Image</members>
    <members>Lead</members>
    <members>LiveAgentSession</members>
    <members>LiveChatTranscript</members>
    <members>LiveChatTranscriptEvent</members>
    <members>LiveChatTranscriptSkill</members>
    <members>LiveChatVisitor</members>
    <members>Macro</members>
    <members>MacroAction</members>
    <members>MacroInstruction</members>
    <members>MacroUsage</members>
    <members>NamespaceRegistry</members>
    <members>NetworkMember</members>
    <members>Opportunity</members>
    <members>Order</members>
    <members>OrgMetricScanResult</members>
    <members>OrgMetricScanSummary</members>
    <members>PartnerFundAllocation</members>
    <members>PartnerFundClaim</members>
    <members>PartnerFundRequest</members>
    <members>PartnerMarketingBudget</members>
    <members>PartyConsent</members>
    <members>PaymentAuthorization</members>
    <members>Pricebook2</members>
    <members>ProcessException</members>
    <members>Product2</members>
    <members>PromptAction</members>
    <members>QuickText</members>
    <members>QuickTextUsage</members>
    <members>Recommendation</members>
    <members>RecordAction</members>
    <members>RecordMergeHistory</members>
    <members>RequestsForAccessSIQ</members>
    <members>Scorecard</members>
    <members>ScorecardAssociation</members>
    <members>ScorecardMetric</members>
    <members>ScratchOrgInfo</members>
    <members>SocialPersona</members>
    <members>Solution</members>
    <members>StreamActivityAccess</members>
    <members>StreamingChannel</members>
    <members>Task</members>
    <members>User</members>
    <members>UserProvisioningRequest</members>
    <name>CustomObject</name>
  </types>
<version>51.0</version>
</Package>

For that initial pain, Salesforce Package.xml Generator Extension for VS Code could make it easier to generate the package.xml. Once you have it, it's a matter of re-using it to pull in your changes.

However, as mentioned above, profiles will only return what you retrieve with it. As such, if you retrieve profiles, apex classes, and object you will be missing a lot of other dependent metadata depending on what you have set on it (profiles will be incomplete).

  • Apex Class
  • Apex Pages
  • Custom Applications
  • Custom Objects
  • Custom Permission
  • Custom Tab
  • External Data Sources
  • Flow Definition
  • Layout
  • Profile Password Policy
  • Profile Session Setting

Using git will be helpful to double check what you're changing when you retrieve as the only changes should make sense (new access for your project related objects/classes).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .