51

There are ways to surface the namespace itself from within Apex (doesn't help us in JavaScript, yet). Deriving the namespace prefix itself: String rawPrefix = MyClass.class.getName().substringBefore('MyClass').substringBefore('.'); //this gives '' in any development org //and gives 'ns' in the packaging org Getting a single token which can be used to ...


33

I realize this is a little late in coming, but for posterity's sake, if you append the namespace to the front of your visualforce page name, salesforce will make sure it gets the proper namespace in the full url. So if you want your action to go to /apex/MyPage, you would do this: /apex/c__MyPage If you're linking to something in a managed package you ...


26

No no, the field (API) name is Schematic__c, you need to start from it. Think about Schematic__r (the rel. name) like a consistent table alias when you'd make JOINs in regular database, nothing more. To go "up": Schema.DescribeFieldResult f = Schema.sObjectType.Order_Line_Item__c.fields.Order__c; System.debug(f.getRelationshipName()); // Outputs "...


14

In the project configuration file, specify the namespace. { "packageDirectories" : [ { "path": "force-app", "default": true} ], "namespace": "myns", "sfdcLoginUrl" : "https://login.salesforce.com", "sourceApiVersion": "44.0" } This really only alluded to in the documentation, but sfdx-project.json is the key to creating a scratch org with a ...


13

There's a glitch with Visualforce pages regarding namespaces. The workaround is to always use a Visualforce input or output element. <!-- this is bad --> {!Account.PackagedField__c} <!-- this is good --> <apex:outputField value="{!Account.PackagedField__c}" /> After installing the package in another org, you'll see that salesforce ...


13

Spotted in the Spring `16 release notes under Changed Objects: Organization The following new fields have been added: NamespacePrefix SignupCountryIsoCode—Represents the two-character ISO country code specified by the user for a sign-up request. It appears it will now be possible to directly query for the NamespacePrefix using SOQL ...


13

I was able to recreate the issue, and although I don't know what is causing it, I was able to get past it by changing the name of the apex class: public class MyContactListControllers { @AuraEnabled public static List<Contact> getContacts() { return [Select Id, Name, Email, Title, Phone From Contact]; } } and then making the ...


11

There is the possibility of installing the package using Metadata API. Then inspect the company details, package version description or documentation (etc) for meaningful contact information. For example using JavaScript in browser console: var versionNumber = '1.0'; var activateRSS = 'false'; var nsPrefix = 'MyCompanyName'; var binding = new ...


9

Query for it, using a class that you know will be there: ApexClass myClass = [ select NamespacePrefix from ApexClass where Name = 'SomeClassNameHere' ];


9

So, this is the Maximum number of unique namespaces referenced limit, which currently maxes out at 10. The explanation from the linked documentation: In a single transaction, you can only reference 10 unique namespaces. For example, suppose you have an object that executes a class in a managed package when the object is updated. Then that class updates a ...


8

Spotted in the Spring `16 release notes under Changed Objects: Organization The following new fields have been added: NamespacePrefix SignupCountryIsoCode—Represents the two-character ISO country code specified by the user for a sign-up request. It appears it will now be possible to directly query for the NamespacePrefix without needing ...


8

Based on the error message at line 14 of CustomObjects.onAfterInsert() you're doing a query of EntitySubscription without a limit. You'll need to put a limit of at least 1000 on it. You're only getting the error message when the method is called via the SObjectDomain class because it has a "with sharing" directive. As @ca_petersen pointed out in the ...


6

Once you have a managed package you will know the Org id of your packaging org (and that's never going to change). In your code you could check the Org Id using UserInfo.getOrganizationId() against the packaging org id (hard-coded) (1) the namespace will be present, but the org id will not be the same as the packaging org id (2) the namespace will be ...


6

I found that the describe map was only partially case-insensitive:- Schema.getGlobalDescribe().get('CustomObject__c'); // works Schema.getGlobalDescribe().get('customobject__c'); // works Schema.getGlobalDescribe().get('ns__CustomObject__c'); // works Schema.getGlobalDescribe().get('Ns__CustomObject__c'); // doesn't work So object names are ...


6

Thats a current limitation of the platform .The Javascript file does not get namespace added unlike visualforce pages for managed package . I wrote a blog post on this . The best way would be to create a message layer or a wrapper class like your second approach and that avoids the problem .The only caveat is you end up writing bunch of classes .


6

Salesforce has an idea for organizing code. It's eight years in the making, but it is under PM review, so they're at least considering it. Also, once Salesforce DX comes out, we'll have "artifacts", which lets us put code into folders for organizational purposes, but those only apply in your repository, not on the server itself. For now, what many ...


6

The answer to this is to use Salesforce DX, which will be released any day now. DX allows you to create new dev orgs that all share the same namespace as the packaging org. This makes it a lot easier to deal with the namespace, since all orgs you develop and test in will have the correct namespace. If you don't want to move DX, your next best choice is to ...


5

Use the URLFOR function in conjunction with the $Page global variable. e.g. action="{!URLFOR($Page.Your_VF_Page_Name,[params])}" Another way of doing this is returning a PageReference to Page.Your_VF_PageName in a controller. Yes, you can pass in parameters using this technique. Yes, it will resolve your namespace correctly. In my opinion, using the ...


5

Does Schema.GetGlobalDescribe() Account for Prefixes? Yep! Use SObjectType.Obj__c.Name to resolve the namespace, for example: Static method: String fullyQualifiedName = SObjectType.Obj__c.Name; System.debug(fullyQualifiedName); //ns__Obj__c String label = Schema.GetGlobalDescribe().get(fullyQualifiedName).getDescribe().getLabel(); System.debug(label); //...


5

Support for relative/current namespace refs (c:blah) is available in Spring '15 which will be hitting production soon. In markup you really do not have many options for minimizing the maintainable issue currently. We tried to get this in sooner but it was a bit tricker to layer on top of Aura than we had hoped. FYI Spring '15 also supports non-namespaced ...


5

Typically you don't have to revisit all of your code. Most things will continue to run after the prefix is added. But most doesn't mean all. I found these points requiring modifications: Objects accessed via API as a consequence existing integrations and ETL processes Metadata accessed via API including use of Metadata Service.cls for APEX Usage of Ajax ...


5

The simplest way to have a conditional namespace in a remote action invocation is like this: (namespace||window).controller.method( ... );


5

This has been solved with Summer 16 release now . <aura:component> <!-- Stand-alone static resources --> <img src="{!$Resource.generic_profile_svg}"/> <img src="{!$Resource.yourNamespace__generic_profile_svg}"/> <!-- Asset from an archive static resource --> <img src="{!$Resource.SLDSv1 + '/assets/images/avatar1.jpg'}"/> ...


5

There are several ways to achieve this: Querying the namespaceprefix. You can perform query on ApexClass to find if namespace exist or not. eg. ApexClass cs =[select NamespacePrefix from ApexClass where Name =:'<name of the class from your package>']; Create a field in custom setting(Hierarchy) which will contain the namespaceprefix. Hierarchy type ...


5

In my experience, the partial solution is to eliminate any duplicate field names via a set when creating a dynamic query of this form. This avoids an error when the query runs, but you will only get access to the namespaced version of the field not the locally added non-namespaced field. It is an unfortunate limitation of the platform at the moment that you ...


5

I thought this would not work but it seems to in one of my development org with the component bundle version set to 40.0 (so locker should be enabled) console.log(component.getConcreteComponent().getDef().getDescriptor().getNamespace()); Which outputs the namespace for the component. No idea if it will continue to work or is scheduled to be removed so use ...


5

If the class you're interested in looking for is global, you can save a query by using Type.forName(namespacePrefix, className). In all other cases, you should be able to at least query for the given ApexClass to confirm its presence, but you won't be able to interact with it in any way.


5

This is part of the critical update documented here https://releasenotes.docs.salesforce.com/en-us/spring20/release-notes/rn_apex_publicConstructorsInMgdPackages.htm?edition=&impact= Specifically "Apex classes contained in second-generation packages can instantiate public classes from other packages in the same namespace only if they are annotated @...


4

You can create a managed and unmanaged package in the same organization, and the components can be shared between the two. We have successfully done this with a package containing 500 classes, about 1000 fields over 20 custom objects, and hundreds of Visualforce pages and components. Usually, errors in a non-namespaced version occurs because there are ...


4

I have suffered this error in the past as well, and we followed the same approach as sfdcfox. In our Visualforce pages, we added a list of outputfields linked to the related sObject fields, and set rendered attribute to false to avoid displaying them: <apex:outputField value="{!MyCustomObject__c.MyCustomField__c}" rendered="false"/>


Only top voted, non community-wiki answers of a minimum length are eligible