0

I have a simple lightning component with a list of Orders that shows up as expected when I add it to a Lighning page in my org, but is blank when I add it to a Community/Experience Cloud page.

I've verified that the profile for the community user has access to the object and all the fields, and I've updated the metadata file to make the component available to add to community pages (I can add the component, but no data shows up).

Why would this component render data internally but not in a community?

Here's the metadata file:

<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
   <apiVersion>51.0</apiVersion>
   <isExposed>true</isExposed>
<targets>
   <target>lightning__AppPage</target>
   <target>lightning__RecordPage</target>
   <target>lightning__HomePage</target>
   <target>lightningCommunity__Page</target>
   <target>lightningCommunity__Default</target>
</targets>

</LightningComponentBundle>

Here's the js:

import { LightningElement,wire } from 'lwc';

/** CustomerOrdersController.getOrders Apex method */
import getOrders from '@salesforce/apex/CustomerOrdersController.getOrders';
export default class OrderList extends LightningElement {
   @wire(getOrders) orders;
}

Here's the HTML:

<template>
<lightning-card title="Orders">
    <div class="slds-card__body_inner">
        <!-- Start order list -->
        <template if:true={orders.data}>
            <lightning-layout multiple-rows="true" pull-to-boundary="small">
                <template for:each={orders.data} for:item="o">
                    <lightning-layout-item key={o.Id} size="3" class="slds-var-p-around_x-small">
                        <!-- Start order tile -->
                        <lightning-card title={o.Order_Id__c} >
                            <div class="slds-var-p-horizontal_small">
                                <div class="slds-media">
                                    
                                    <div class="slds-media__body">
                                        <p class="slds-var-m-bottom_xx-small">PO: {o.PoNumber}</p>
                                        <p class="slds-var-m-bottom_xx-small">Status: {o.Order_Status__c}</p>
                                        <p class="slds-var-m-bottom_xx-small">Tracking Number: {o.Tracking_Number__c}</p>
                                    </div>
                                </div>
                            </div>
                        </lightning-card>
                        <!-- End order tile -->
                    </lightning-layout-item>
                </template>
            </lightning-layout>
        </template>
        <!-- End order list -->
        <!-- Data failed to load -->
        <template if:true={orders.error}>
            <div class="slds-text-color_error">
                An error occurred while loading the list: {error.message} 
            </div>
        </template>
    </div>
</lightning-card>

Here's the Apex controller:

public with sharing class CustomerOrdersController {
@AuraEnabled(Cacheable=true)
public static order[] getOrders() {
        return [
            SELECT 
                Id, 
                Name,
                Order_Id__c,
                PoNumber,
                Order_Status__c,
                Service_Order_Start_Date_Time__c,
                Product_Confirm_Date__c,
                Effective_Total_All_Orders__c,
                Tracking_Number__c 
            FROM Order
            WHERE Type != 'Change Order' 
                AND PO_Override_by_Sales_Manager__c = False 
                AND PoNumber != null
            LIMIT 20
        ];
   }
}
2

We need to Set Up Sharing Sets for Order objects

Set Up Sharing Sets

check the above link for more info

1
  • I have set up Sharing Sets for the Order object - the customer user has access to all of the records I'm trying to show. If I add a list view with the same parameters as the SOQL query, they are able to see the records, but they are not able to see them in the LWC. – TheDevAdmin Mar 9 at 23:40
1

Found the issue. The community user profile needs to be given access to the Apex Class that is the controller.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.