0

We have a managed package installed in about 1800 different orgs and, as such, there are multiple versions of the managed package out there. I'm trying to write an unmanaged package that will interact with those different versions. Doing so is giving me a "Variable does not exist" error due to a field not existing in the older version that does in the newer version. I've written a check to see if the field exists and put the variable inside an if statement but that doesn't resolve the error.

So I have

sObjTemplate = new nihrm__DocumentTemplate__c();

merge2 = doesFieldExist ('nihrm__DocumentTemplate__c','mycustomfield__c');

if(merge2){sObjTemplate.mycustomfield__c = merge2Sel;}

My development environment is running the lowest version so mycustomfield__c doesn't exist and, as such, throws the "Variable does not exist" error. Is there a way around this? Or do I have to have multiple dev orgs at multiple versions of the managed package and create multiple unmanaged packages for them?

I'm hoping I've written this in a way that makes sense. Basically I'm looking for something similar to a conditional compile so I can get this code to work on multiple versions.

1 Answer 1

2

You can't be "conditional," but you can be "dynamic."

if(merge2) {
  sObjTemplate.put('mycustomfield__c',merge2Sel);
}

The put method avoids the compilation error when a field doesn't exist.

By the way, you might want to consider an Unlocked Package rather than an Unmanaged Package. They offer all the same benefits of an Unmanaged Package, while still being upgradeable if you need to fix bugs or add features.

3

You must log in to answer this question.

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