2

We're ISV and already built quite a few managed packages. We've been including a namespace prefix everywhere in code (Apex classes, Lightning components etc.) as it's recommended by Salesforce. Now we want to start new projects with Salesforce DX. We know that it's not necessary to add a namespace prefix when you push your code to scratch orgs but should we add namespace when we deploy this code to release org? From my understanding, some code will not be deployed because a namespace prefix is missing, correct?

Thanks in advance!

0

1 Answer 1

2

Normally, you would link a namespace to your DevHub. Once you do this, you can create scratch orgs with the namespace pre-configured in the scratch org definition file. However, generally speaking, you should not include your namespace prefix in your source (I think there's a few exceptions), as the deployment process should automatically do this for you when appropriate.

8
  • Are there any downsides to choosing to do it anyway? Will the deployment fail if I were to include the prefix?
    – gNerb
    Jul 16, 2018 at 20:11
  • @gNerb If you don't link the name space, but you do include the prefix, you'll get compilation errors related to unknown namespace/prefix errors.
    – sfdcfox
    Jul 16, 2018 at 20:13
  • I think the question is more related to prod orgs. I haven't worked with DX much, does DX allow for deployment to a prod org? How does that differ from installing via the app exchange? Does code uploaded to the app exchange need the prefix or is that still handled automatically? I'm sure you can tell I have no idea about any of this. I like this question because I think a good thorough answer could help alot of people (like me and the OP apparently).
    – gNerb
    Jul 16, 2018 at 20:19
  • 1
    @gNerb You can deploy to a production org, even install packages, but then it's an AppExchange install (not your local source). You can't deploy code in to a managed package in production, so the only legitimate use (for namespace prefix) is for ISV development. Code uploaded to the AppExchange automatically appends namespace as appropriate; you don't need it in your source. I would solidly state that you should avoid use of the namespace except in situations where it is necessary (the exceptions are few, and typically show up during testing).
    – sfdcfox
    Jul 16, 2018 at 20:29
  • @sfdcfox thanks for the quick answer, we were adding a namespace prefix to avoid naming conflicts. I don't understand if it's automatically done while deployment why Salesforce recommends to add a namespace to prevent naming conflicts? For instance developer.salesforce.com/docs/atlas.en-us.packagingGuide.meta/… Jul 16, 2018 at 20:33

You must log in to answer this question.

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