0

I've encountered a problem. I'm writing code in our developer org where we have a managed package installed (this package is ours as well). I'm trying to call a method of an apex class defined in that installed package, but when deploying, a "method is not visible" error is thrown.

global void execute(Database.BatchableContext BC, List<ERPvs__Comprobante_Punto_De_Venta__c> scope){
    
    for(ERPvs__Comprobante_Punto_De_Venta__c cpv : scope){
        try{
            if(cpv.ERPvs__Empresa__r.ERPvs__Empresa_UY__c){
                ERPvs.FacturacionElectronicaController.generarPDFCPVUY(cpv.Id);
            }else{
                ERPvs.FacturacionElectronicaController.generarPDFCPV(cpv.Id);
            }
        }catch(Exception e){
            body += 'LN' + e.getLineNumber() + '-' +cpv.Id + '-' + cpv.Name + ' - Error en PDF: ' + e.getMessage() + '\n';
        }
    }  
    
}

As you can see, I am calling two methods there. The method in the else block was already being called before with no problem, and I'm trying to add the call to the first method, that is the one that is throwing the not visible error.

The thing is, both methods are declared the same way in the "FacturacionElectronicaController" class in the managed package:

WebService static String[] generarPDFCPV(String cpvId){
    String[] result = new String[2];
    result[0] = '1';
    ApexLogger.Debug(LoggingLevel.WARN,'>> cpvId: '+cpvId);
    try{
        doGenerarPDFCPV(cpvId);
    }catch(Exception e){
        result[0] = '0';
        result[1] = e.getMessage() + ' - Línea ' + e.getLineNumber() + ': ' + e.getStackTraceString();
    }
    
    return result;
}



WebService static String[] generarPDFCPVUY(String cpvId){
    String[] result = new String[2];
    result[0] = '1';
    ApexLogger.Debug(LoggingLevel.WARN,'>> cpvId: '+cpvId);
    try{
        doGenerarPDFCPVUY(cpvId);
    }catch(Exception e){
        result[0] = '0';
        result[1] = e.getMessage() + ' - Línea ' + e.getLineNumber() + ': ' + e.getStackTraceString();
    }
    
    return result;
}

(Both methods being called there are declared as public so it should work)

As per the documentation:

Methods defined with the webservice keyword are inherently global. Any Apex code that has access to the class can use these methods. You can consider the webservice keyword as a type of access modifier that enables more access than global.

So why is the compiler throwing not visible? Am I missing something?

EDIT: I've researched a little further, and found something about version settings for the apex classes, maybe it has something to do about this? The thing is I looked for the managed package class to see the signatures of the methods available and the one I'm trying to access is there:

enter image description here

4
  • Are the methods in the managed package global? Only global methods can be called from a managed package as they're exposed to the rest of the org. Note that once a method is global in a package it can never be removed or have it's parameters changed (though you can overload)
    – Matt Lacey
    Jan 4, 2023 at 14:29
  • @MattLacey Hey! the two methods being called are the ones with the webservice annotation... As I understand, those are inherently global as per the documentation. Jan 4, 2023 at 14:31
  • Ah fair point - it's been a long time since I used that keyword.... more than ten years I think!
    – Matt Lacey
    Jan 6, 2023 at 11:13
  • @MattLacey I'm sure of that.. Sadly in my company we have a lot of old code, because most of our clients use Salesforce Classic still... So many buttons using onclick javascript and old tech. We are trying to update as much as we can. Jan 9, 2023 at 13:45

1 Answer 1

0

The problem was in the managed package version defined in the version settings of my class in which I was trying to write the code. The version that was manually defined was an older version, and the global method I was trying to call wasn't even available then.

Version settings can be found in the class definition in the org configuration or can be manually changed in the meta-xml file of the apex class.

You must log in to answer this question.

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