1

I have Managed Package which is installed in my Dev Org.

This package contains some Apex Methods which I want to import into my LWC in the Dev Org.

The Apex Class and Method marked as global in the Package org.

global class GlobalUtility {
    global static Boolean isUserLicenced(Id userId) {
        Boolean isUserLicenced = false;
        // do some logic
        return isUserLicenced ;
    }
}

However I still can't import them into my LWC, i have tried different variants:

// should be the correct one
import isUserLicenced from '@salesforce/apex/packageName.GlobalUtility.isUserLicenced'; 
// however it gives "Unable to find Apex action method referenced as 'packageName.GlobalUtility.isUserLicenced'." error

// not working as it search for local classes
import isUserLicenced from '@salesforce/apex/GlobalUtility.isUserLicenced'; 
// not working as it search for local "packageName__GlobalUtility" class
import isUserLicenced from '@salesforce/apex/packageName__GlobalUtility.isUserLicenced'; 

In the docs: Component Namespaces, I see that:

A custom Lightning web component can't access a Lightning web component or module in a custom namespace when running in an org that’s using Lightning Locker instead of Lightning Web Security

I do have Lightning Web Security enabled !!

However it is about other LWC's and modules from package, not about Apex Classes !!

So my Question is:

Can we import Apex method from Managed Package into our local LWC ??

Any help will be appreciated,
thanks

1 Answer 1

2

I've never gotten to work, either, but conceptually, you'd just write a local class to bridge the gap:

public class MyUtils {
  @AuraEnabled public static Boolean isUserLicensed(Id userId) {
    return packageName.GlobalUtility.isUserLicensed(userId);
  }
}
3
  • 1
    Ohh, I just understand I am missing "@AuraEnabled" on the Global method declaration. Will try with it. However your variant is pretty good. May 19, 2023 at 19:04
  • 1
    @VitaliiDehnerys Yeah, now you mention it, I see that, too. That was probably my problem back in the day, too.
    – sfdcfox
    May 19, 2023 at 19:57
  • Just to confirm, I added "@AuraEnabled" to the Global method declaration and it works perfectly. May 22, 2023 at 10:48

You must log in to answer this question.

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