3

I am currently migrating to a managed package and I wish I could copy unmanaged [protected -- in case it matters] custom settings values to the managed ones in my post install script.

However, I'm getting the following exception when trying to query the unmanaged CS:

Custom Setting cannot be referenced outside code from the same namespace.

Does it mean I won't be able to copy them automatically? What is the best way to copy them then? I think I'm going to have to serialize them via unmanaged code but maybe there's a better way to do it.

This post says that 'without sharing' would grant my post install script with access to all data but it doesn't seem to be working for my unmanaged custom settings.

Thanks

2
  • Does the managed custom setting and the unmanaged custom setting have the same name? Eg ns__Setting__c and Setting__c Commented Apr 21, 2015 at 17:44
  • I've tried different names as well.
    – user39399
    Commented Apr 22, 2015 at 7:56

1 Answer 1

2

Sharing is independent of the public/protected custom settings distinction, just like it's independent of the difference between a global apex method and a merely public one.

Protected custom settings can only be accessed by code within their namespace. Since unmanaged things are treated as being in the customer's organization's namespace (the "empty namespace" counts, if the customer hasn't set a namespace on their organization), code in managed packages, including code in post-install scripts, can't read it.

You could serialize it via unmanaged code, as you say, or simply copy it into an unmanaged public custom setting or a custom object, and have your post-install script copy from there into the packaged, protected custom setting.

You must log in to answer this question.

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