Skip to main content
edited body
Source Link
Matt and Neil
  • 33.1k
  • 7
  • 107
  • 189

I'm using this pattern provided by @bigassforce@mattandneil here How can I get organization's namespace prefix or at least ALL namespace prefixes including org through any API

String qualifiedUrl = new PageReference('/apex/').getUrl();
return url.substringBefore('__').substringAfterLast('/');

This was provided as the "Organization Namespace Prefix", which wrong, but it has provided the Namespaceprefix of the current Managed Package (if executed inside a installed package and '' if executed not inside a MP). This is exactly what I need: not the Orgs-Namespace but that from the package.

Now today I have encountered one single production Org, where it does not work. This line creates an Internal Salesforce Error when run in execute anonymous:

String qualifiedUrl = new PageReference('/apex/').getUrl();

The error goes like this:

Line: -1, Column: -1 The name can only contain underscores and alphanumeric characters. It must begin with a letter and be unique, and must not include spaces, end with an underscore, or contain two consecutive underscores.

The strange thing is, that on a sandbox, spun today this code DOES WORK. The sandbox is not changed after spinning!

Now I'm looking for either a reason, why this code might fail or a alternative code, doing the same but not using any reference to an SObject or anything custom in the org. This code must run inside a utility class (used for various managed and unmanaged code) and therefore I can not assume any custom metadata present - maybe except of the utility class itself.

I'm using this pattern provided by @bigassforce here How can I get organization's namespace prefix or at least ALL namespace prefixes including org through any API

String qualifiedUrl = new PageReference('/apex/').getUrl();
return url.substringBefore('__').substringAfterLast('/');

This was provided as the "Organization Namespace Prefix", which wrong, but it has provided the Namespaceprefix of the current Managed Package (if executed inside a installed package and '' if executed not inside a MP). This is exactly what I need: not the Orgs-Namespace but that from the package.

Now today I have encountered one single production Org, where it does not work. This line creates an Internal Salesforce Error when run in execute anonymous:

String qualifiedUrl = new PageReference('/apex/').getUrl();

The error goes like this:

Line: -1, Column: -1 The name can only contain underscores and alphanumeric characters. It must begin with a letter and be unique, and must not include spaces, end with an underscore, or contain two consecutive underscores.

The strange thing is, that on a sandbox, spun today this code DOES WORK. The sandbox is not changed after spinning!

Now I'm looking for either a reason, why this code might fail or a alternative code, doing the same but not using any reference to an SObject or anything custom in the org. This code must run inside a utility class (used for various managed and unmanaged code) and therefore I can not assume any custom metadata present - maybe except of the utility class itself.

I'm using this pattern provided by @mattandneil here How can I get organization's namespace prefix or at least ALL namespace prefixes including org through any API

String qualifiedUrl = new PageReference('/apex/').getUrl();
return url.substringBefore('__').substringAfterLast('/');

This was provided as the "Organization Namespace Prefix", which wrong, but it has provided the Namespaceprefix of the current Managed Package (if executed inside a installed package and '' if executed not inside a MP). This is exactly what I need: not the Orgs-Namespace but that from the package.

Now today I have encountered one single production Org, where it does not work. This line creates an Internal Salesforce Error when run in execute anonymous:

String qualifiedUrl = new PageReference('/apex/').getUrl();

The error goes like this:

Line: -1, Column: -1 The name can only contain underscores and alphanumeric characters. It must begin with a letter and be unique, and must not include spaces, end with an underscore, or contain two consecutive underscores.

The strange thing is, that on a sandbox, spun today this code DOES WORK. The sandbox is not changed after spinning!

Now I'm looking for either a reason, why this code might fail or a alternative code, doing the same but not using any reference to an SObject or anything custom in the org. This code must run inside a utility class (used for various managed and unmanaged code) and therefore I can not assume any custom metadata present - maybe except of the utility class itself.

replaced http://salesforce.stackexchange.com/ with https://salesforce.stackexchange.com/
Source Link

I'm using this pattern provided by @bigassforce here How can I get organization's namespace prefix or at least ALL namespace prefixes including org through any APIHow can I get organization's namespace prefix or at least ALL namespace prefixes including org through any API

String qualifiedUrl = new PageReference('/apex/').getUrl();
return url.substringBefore('__').substringAfterLast('/');

This was provided as the "Organization Namespace Prefix", which wrong, but it has provided the Namespaceprefix of the current Managed Package (if executed inside a installed package and '' if executed not inside a MP). This is exactly what I need: not the Orgs-Namespace but that from the package.

Now today I have encountered one single production Org, where it does not work. This line creates an Internal Salesforce Error when run in execute anonymous:

String qualifiedUrl = new PageReference('/apex/').getUrl();

The error goes like this:

Line: -1, Column: -1 The name can only contain underscores and alphanumeric characters. It must begin with a letter and be unique, and must not include spaces, end with an underscore, or contain two consecutive underscores.

The strange thing is, that on a sandbox, spun today this code DOES WORK. The sandbox is not changed after spinning!

Now I'm looking for either a reason, why this code might fail or a alternative code, doing the same but not using any reference to an SObject or anything custom in the org. This code must run inside a utility class (used for various managed and unmanaged code) and therefore I can not assume any custom metadata present - maybe except of the utility class itself.

I'm using this pattern provided by @bigassforce here How can I get organization's namespace prefix or at least ALL namespace prefixes including org through any API

String qualifiedUrl = new PageReference('/apex/').getUrl();
return url.substringBefore('__').substringAfterLast('/');

This was provided as the "Organization Namespace Prefix", which wrong, but it has provided the Namespaceprefix of the current Managed Package (if executed inside a installed package and '' if executed not inside a MP). This is exactly what I need: not the Orgs-Namespace but that from the package.

Now today I have encountered one single production Org, where it does not work. This line creates an Internal Salesforce Error when run in execute anonymous:

String qualifiedUrl = new PageReference('/apex/').getUrl();

The error goes like this:

Line: -1, Column: -1 The name can only contain underscores and alphanumeric characters. It must begin with a letter and be unique, and must not include spaces, end with an underscore, or contain two consecutive underscores.

The strange thing is, that on a sandbox, spun today this code DOES WORK. The sandbox is not changed after spinning!

Now I'm looking for either a reason, why this code might fail or a alternative code, doing the same but not using any reference to an SObject or anything custom in the org. This code must run inside a utility class (used for various managed and unmanaged code) and therefore I can not assume any custom metadata present - maybe except of the utility class itself.

I'm using this pattern provided by @bigassforce here How can I get organization's namespace prefix or at least ALL namespace prefixes including org through any API

String qualifiedUrl = new PageReference('/apex/').getUrl();
return url.substringBefore('__').substringAfterLast('/');

This was provided as the "Organization Namespace Prefix", which wrong, but it has provided the Namespaceprefix of the current Managed Package (if executed inside a installed package and '' if executed not inside a MP). This is exactly what I need: not the Orgs-Namespace but that from the package.

Now today I have encountered one single production Org, where it does not work. This line creates an Internal Salesforce Error when run in execute anonymous:

String qualifiedUrl = new PageReference('/apex/').getUrl();

The error goes like this:

Line: -1, Column: -1 The name can only contain underscores and alphanumeric characters. It must begin with a letter and be unique, and must not include spaces, end with an underscore, or contain two consecutive underscores.

The strange thing is, that on a sandbox, spun today this code DOES WORK. The sandbox is not changed after spinning!

Now I'm looking for either a reason, why this code might fail or a alternative code, doing the same but not using any reference to an SObject or anything custom in the org. This code must run inside a utility class (used for various managed and unmanaged code) and therefore I can not assume any custom metadata present - maybe except of the utility class itself.

edited title
Link
Uwe Heim
  • 28.5k
  • 20
  • 121
  • 287

Get Why PageReference('/apex/').getUrl() fails on some Orgs and how to get NamespacePrefix from inside a Managed Package without using a SObject?

Tweeted twitter.com/StackSalesforce/status/775699322612641792
Source Link
Uwe Heim
  • 28.5k
  • 20
  • 121
  • 287
Loading