2

1) When Querying namespace_X__object1__c like so:

namespace_X__object1__c sm = Database.Query('Select Id, Name, Security_Description__c, product_type__c from namespace_X__object1__c where id=:objectId');

I'm unclear how to access fields Security_Description__c, product_type__c - as these two fields are added as part of namespace_Y app. So, now how do I access the 'sm' object fields (name, Security_Description__c, product_type__c) ?

securityDescr = sm.Security_Description__c; 

OR

securityDescr = sm.namespace_Y__Security_Description__c;

2) Should we use the namespace when we are accessing the Custom Settings inside the Managed package Apex Controller? (NOTE: Custom settings and Apex controller belong to the same package)

3) After creating a namespace - when I create a unmanaged package - I am getting the following error:

line 158, column 30: Unmanaged packages cannot explicitly reference this organization's namespace.

4) After packaging the code with a namespace - where will the next version of development happen? Is it on namespace code or on a no namespace code? if it is on namespace version how is it done?

Thanks and Appreciate your help.

2 Answers 2

2

I'm not clear from your question whether you're trying to build a Managed Package, and a Managed Package is what you actually want (or need). Maybe have a read of this first and decide if a Managed Package is right for your needs, but in summary:

Managed packages are typically used by Salesforce partners to distribute and sell applications to customers

Addressing each of your questions:

  1. How do I access fields Security_Description__c and Product_Type__c on my Object1__c?

This really depends on how Security_Description__c and Product_Type__c came to be on Object1__c. If they were installed as part of namespace_Y 'into' namespace_X, then namespace_Y would have been an extension to namespace_X and you would have had to install first namespace_X and then namespace_Y into your org. In any case, the way to find out the API name of these fields would be to look at the API Name column under Custom Fields & Relationships on Object1__c

2) Should we use the namespace when we are accessing the Custom Settings inside the Managed package Apex Controller?

You should not need to, the code in the managed package will always take preference of its own objects, even if there is an unmanaged object with the same name.

3) After creating a namespace - when I create a unmanaged package - I am getting the following error:

line 158, column 30: Unmanaged packages cannot explicitly reference this organization's namespace.

That error is because you are referencing a managed component (of namespace_X) from something in your unmanaged package. So, imagine if you didn't get this error message and then tried to deploy your unmanaged package to another org, what if namespace_X wasn't installed on your target org? This error is preventing that from happening. If you're creating an unmanaged package, it implies you're trying to release something from namespace_X package. The only way you're going to be able to release something from this org now is by uploading your Managed Package - once you have created a namespace, it is irreversible. If a managed package is not what you want, you would need to spin up a new DE org.

4) After packaging the code with a namespace - where will the next version of development happen? Is it on namespace code or on a no namespace code? if it is on namespace version how is it done?

Once you create a Managed Package, any further modification to the code in namespace_X would need to happen in the DE org for the Managed Package, i.e. if you deploy to a Sandbox, you won't be able to modify the code there.

1
  • Yes, we are building the managed package on top of another managed package. Yes, customers need to install the package-1 first then install our package.
    – Tara
    May 13, 2016 at 16:31
0

There are several things which you can follow in such scenarios(In your scenario see 2nd point):

1.Grab Namespace dynamically.

Note: Only If you really need the namespace of your managed package in which this code is written although it is rarely required.

During development we don't have access to namespace of our own managed package so it's better to grab it dynamically.There could be several ways to achieve this, I'm sharing some:

a. You can provide namespace in custom setting or custom metadata types and grab that from there.I would prefer this approach.

Or

b. You can query the namespace using following query

select id, NameSpacePrefix from ApexClass where Name='NameOfYourAnyClass' 

2. Install parent package first

In case If you have dependency on some other package you have to install it in the org in which you are doing development and you have to refer it's field with namespace.

The same thing will be applied when you will package this dependent code.You have to first install the parent package then migrate code from development to packaging org and then create package.

I'm thinking some more scenarios and maybe i would update my answer with them.

You must log in to answer this question.

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