6

(Edit: all of this is happening only in a Force.com site. The Lightning Web Component is not the source of the problem) I'm trying to query an External Object inside @AuraEnabled method, but I'm getting the following error in LWC:

sObject type 'public_accessories__x' is not supported.

The method works perfectly fine in Anonymous Apex.

So I've changed the return type of the method to a normal sObject:

Here's my method:

@AuraEnabled(Cacheable=true)
public static List<Accessories__c> getAccessories(String uid) {
    List<public_accessories__x> accsExt = [
            SELECT
                    id__c,
                    name__c,
                    type__c
            FROM public_accessories__x
            WHERE uid__c = :uid
            ORDER BY name__c ASC];

    List<Accessories__c> accs = new List<Accessories__c>();
    for (public_accessories__c__x accExt : accsExt) {
        accs.add(new Accessories__c(
                Name = accExt.name__c,
                Type__c = accExt.type__c
        ));
    }

    return accs;
}

But it still gives the same error! Apparently, if a method used in LWC queries an External Object in its body, then it doesn't work in LWC, even if the External Object is not the actual return type. Is that really the case and if yes, is it documented anywhere?

Edit: I did this in Developer Edition. I don't know if it's the same in a normal org because I don't have access to an org with external objects.

Edit2: OK, I've realized what actually causes this: all this time the LWC was embedded in a Force.com Site. I completely forgot about this fact. When the LWC is accessed normally from withing Salesforce, it works OK with external objects. But I still don't know why it doesn't work in Force.com Site. The Public Access profile has the permissions to the External Object.

  • It looks like you are missing the cacheable=true annotation: developer.salesforce.com/docs/component-library/documentation/… public with sharing class ContactController { @AuraEnabled(cacheable=true) public static List<Contact> getContactList() { return [SELECT Id, Name, Title, Phone, Email, Picture__c FROM Contact WHERE Picture__c != null LIMIT 10]; } } – Kevin Hill Jul 8 '19 at 17:31
  • @KevinHill Even with Cacheable=true it still doesn't work. – mmm321321 Jul 10 '19 at 17:51
  • 1
    There is a one help doc saying that we have to disable "High Data Volume" option for use in lightning. help.salesforce.com/… – Manjot Singh Sep 25 '19 at 8:52
  • 1
    What you are using for external object oDATA or custom apex? – Manjot Singh Sep 25 '19 at 11:42
  • 1
    Actually I tried using Odata services given in trailhead module.. trailhead.salesforce.com/content/learn/modules/…... it is working fine with aura components... so I don't think this is a lightning issue or developer org issue... This might be issue with Odata service you have implemented – Manjot Singh Sep 26 '19 at 10:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.