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
kzmpkzmp 

How to specify package namespace prefix

Hi guys,

I am developing a SalesForce composite application.

The application actually has a native part as well. The native part get installed as a managed package and will get assigned my org's prefix say: xxxx__ to all object.

Now the composite part (.Net solution) accesses the components without that prefix and it is all blown.

Is there a way to make the webservice be aware of the package prefix.

Currently I have a map of all my custom objects and fields and prepend the prefix but it does not seem the right way of doing things.

I have something like

 

if(objName.EndsWith("__c"))

{

   if(objName == "MycustmoColumn")

      || (objName == "MycutomObject")

return "xxx__" + objName;

}

 

Above I check if the objName that gets passed is any of my custom objects or fields and prepend my package.

Some may say why don't you just use the full object name with the package prefix? Well currently I have my package prefix in my release salesforce account only but I have other testing accounts where I do not have that and also I am not sure what my package prefix is going to be when the app is ready and actually released so I need some flexibility there.

 

Thanks,

Kos

Ispita_NavatarIspita_Navatar

You should make use of metadata API to retrieve package name and namespace and thereby modify your code accordingly.

I am pasting some extract of code from Metadata API documentation , I think it will provide you the necessary pointers.

 

DescribeMetadataResult
The call describeMetadata() returns information about the organization that is useful for developers working with
declarative metadata.
Each DescribeMetadataResult object has the following properties:
Name                                Type                                                        Description
metadataObjects            DescribeMetadataObject[]               One or more metadata components and their attributes.

 

organizationNamespace     string                                           The namespace of the organization. Specify only for

                                                                                                       Developer Edition organizations that can contain a managed

                                                                                                       package. The  managed package
                                                                                                       has a namespace specified when it is created.

 

 

 

for (RunTestFailure failure : rtr.getFailures()) {
String n = (failure.getNamespace() == null ? "" :
(failure.getNamespace() + ".")) + failure.getName();
buf.append("Test failure, method: " + n + "." +
failure.getMethodName() + " -- " +
failure.getMessage() + " stack " +
failure.getStackTrace() + "\n\n");

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.

 

kzmpkzmp

Hi Thank you for your reply.

Let me clarify my problem a little more:

I have one custom object on SalesForce which contains settings say:

sObject: CustomSettings__c

                    Column1: CustomSettingsValue__c

                    Column2: CustomSettingsActie__c

Then I have added columns to the standard objects say:

In Account I have added the following fields:

                  Column1: MyAppCorectionStatus__c

                  Column2: MyAppCorrectionTimeStamp__c

 

All of the above gets packaged into a managed applicatoin on AppExchange so I will know eventually my package prefix but for now I do not know it.

Now I have .Net code from a composite application which has some preconfigured settings stored in SQL Server locally. The settings involve column names so I have the following column names:

                     MyAppCorectionStatus__c

                     MyAppCorrectionTimeStamp__c

                     Name

                     ShippingStreet

In my .Net code I just have a config file setting packagePrefix = "xxx__"

When my .net code tries to access the column names that I have it runs them through a addPackagePrefix method.

The problem is that there is no easy way to identify that Name and ShippingStreet should not need the "xxx__" package prefix while MyAppCorectionStatus__c and MyAppCorrectionTimeStamp__c and all things in my custom sObject: CustomSettings__c need this prefix.

When I am in dev invironment I just set in my config file for packagePrefix = "" so there is no package prefix so I can continue work with my settings.

Finally to state what my problem is:

I need to be able to find out to which columns I should add the package prefix and if there is a way that can happen transparently i.e. the API to handle that. I want to say:

select MyAppCorrectionTimeStamp__c,MyAppCorectionStatus__c , Name from account

and the API to figure out that the MyAppCorrectionTimeStamp__c and MyAppCorectionStatus__c columns need the "xxx__" package prefix.

My problem is not being able to find out what the package prefix is.

 

Thanks,

Kos

dkadordkador

The easy answer to your question is that any custom object name or relationship has "__c" as part of its name.  Those are the things you'll need to prepend your namespace prefix to.

 

The even easier answer is to use the DefaultNamespaceHeader in our SOAP APIs.  See our documentation for more details.

kzmpkzmp

Hi,

thank you for your reply.

That was exactly what I was doing, prepending my package prefix to all fields ending in __c but not all custom fields are made from my packege. My package also works with user's custom fields so that is where I had a problem.

I cannot easily distinguish my custom fields from other's people custom fields.

 

I will take a look at the header that you mention. Would using that header solve the problem?

 

Regards,

Kos

dkadordkador

Oh, if you have that problem you'll always have to use the describe result.  That will give you the fully qualified name which includes the namespace prefix.

 

That's without using the header, of course.  The header should solve this problem for you (unless you want to be able to reference things in other managed packages that have different namespace prefixes).