function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Cannot upload Apex that references a namespace in an unmanaged package

Here is a RULE that makes no sense to me. 



"An Apex script contained in an unmanaged package that explicitly references a namespace cannot be uploaded"

[page 171 of the Apex Lanaguage Reference] 


Why can you develop with a namespace and not be allowed to upload it in an unmanaged package?

The namespace is still part of the unmanaged package. The custom buttons and links require the namespace, even in an unmanaged package.

Maybe there's a reason for it, but it just don't makes sense to me. Without the namespace, you don't even get the text highlighting in Eclipse.




The namespace isn't actually a part of the unmanaged package.  Only managed packages have namespaces. You can either:


1. Create and upload a managed package from your org.

2. Remove the namespace references from your code and then you should be able to upload it in an unmanaged package.


This restriction only applies to apex code with namespace references as it will not function in the target org since the namespace isn't present. 


Thanks for your reply.

So you're also saying that the custom links and buttons (URLFOR) need to have the namespace added or removed depending upon if you're going to make a managed package?


For example, I have a custom list button for an appointment object which sends the user to the AppointmentModification.Page. Our namespace is i360, so the button is defined as:

{!URLFOR( "/apex/i360__AppointmentModification", null, [ cid=i360__Lead_Source__c.Id ], false)}


If I try to add this to an unmanaged package, you're saying I'd have to remove the i360__ from both objects?

because this it will not work without the prefix in a managed package.



If the button is in the managed package, then yes, you'll likely need the namespace.  


If it is in the unmanaged package, then you won't want the namespace.  Since unmanaged components can be edited in the subscriber's org, you can make the change after you install it.  The upload shouldn't be blocked by this.  Only namespaces referenced in apex code can block unmanaged package uploads.