I was searching on the web but did not find exactly the answer (I think it is no). I have a 1st generation package with a given namespace, and I would like to create a new package dependent on the first one. Ideally I would like to create it as a 2GP, with the same namespace, is this possible? It seems the answer is no from this link, but it doesn't say if the packages are dependent from each other. Thank you.
1 Answer
In a word: no.
This is covered in the documentation:
If the 1GP and 2GP share a namespace, you can’t install them in the same org.
It doesn't matter if there's a dependency or not, you cannot do this because you cannot install both on the same org.
Based on questions in the comments, the following points should be noted:
- A 1GP can have 2GP extension packages as long as the latter package(s) use a different namespace to the 1GP.
- If the 1GP provides Apex-based services the 2GP(s) are to use, these must be made
global
so the 2GPs can access them. - The 2GP extension packages can all share the same namespace as each other but if they do, make sure to avoid name clashes. This can be done by providing a package-specific prefix used on all API names originating from that package. This prefixing approach applies to all classes, even those that are neither
global
nor@NamespaceAccessible
since Salesforce does not scope name usage to the package, just to the namespace. Two 2GPs in the same namespace containing a same-named class cannot be installed together on a given org.
-
Hi Phil, ok, thanks a lot for the clarification. So what is the recommended approach to create the new package? Create it as a 2GP but with a different namespace? Or create it as a 1GP and convert it next year when the conversion tool is generally available?– MathildeCommented Nov 4 at 13:19
-
For us, given the lead time until 1GP -> 2GP migration GAs, we created a new namespace for our 2GP extension packages. It is annoying, but fundamentally 1GP and 2GP have to have separate namespaces. Indeed, even with 1GP you have to use a different namespace (engineering multiple 1GPs with a shared namespace would be something of a challenge and if possible still would prevent same-org install!). I would not start with a new 1GP now, at all. I might think about simply adding the new stuff to the existing package if dependencies can be dynamic, or would use 2GP with new namespace.– Phil WCommented Nov 4 at 13:37
-
Also, be aware that Apex classes and triggers must be uniquely named in each 2GP in a given namespace, even if they are non-global. This is a very annoying limitation, again covered in the collision documentation IIRC. We adopted package-specific name prefixes for classes, objects, fields, validation rules, flows etc. to avoid such collisions.– Phil WCommented Nov 4 at 13:39
-
Hi Phil, thank you so much, this is so helpful! Just a last question, if I create now a 2GP with a different namespace, I need to change my apex classes from the current 1GP from public to global, if they are called from the new 2GP components, correct? Thank you!– MathildeCommented Nov 4 at 15:23
-
That is correct @Mathilde. Again, a PITA, but you do what you have to!– Phil WCommented Nov 4 at 16:35