• Marcelo da Silva Velame
  • NEWBIE
  • 5 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
hi i'm working on this activity on this track but i couldn't implement step 5 of the activity in Visual Studio Code

Step 5 talks to comment the code I made in the class and put the activity code, I put it but I can't deploy it to org, it gives an error.

the trailhead activity link:
https://trailhead.salesforce.com/pt-BR/content/learn/modules/lightning-web-components-and-salesforce-data/handle-server-errors


User-added image

My code:
HTML

<template>
<lightning-card>
<template if:true={accounts.data}>
<lightning-datatable
key-field="Id"
data={accounts.data}
columns={columns}
>
<template if:true={errors}>
<p>{errors}</p>
</template>
</lightning-datatable>
</template>
</lightning-card>
</template>

=====================================================
JavaScript

import { LightningElement, wire } from 'lwc';
import NAME_FIELD from '@salesforce/schema/Account.Name';
import REVENUE_FIELD from '@salesforce/schema/Account.AnnualRevenue';
import INDUSTRY_FIELD from '@salesforce/schema/Account.Industry';
import getAccounts from '@salesforce/apex/AccountController.getAccounts';
import { reduceErrors } from 'c/ldsUtils';
const COLUMNS = [
{ label: 'Account Name', fieldName: NAME_FIELD.fieldApiName, type: 'text' },
{ label: 'Annual Revenue', fieldName: REVENUE_FIELD.fieldApiName, type: 'currency' },
{ label: 'Industry', fieldName: INDUSTRY_FIELD.fieldApiName, type: 'text' }
];
export default class AccountList extends LightningElement {
columns = COLUMNS;
@wire(getAccounts)
accounts;
get errors() {
return (this.accounts.error) ?
reduceErrors(this.accounts.error) : [];
}
}

=====================================================
XML

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

=====================================================
APEX CLASS

public with sharing class AccountController {
@AuraEnabled(cacheable=true)
public static List<Account> getAccounts() {
/*return [
SELECT Name, AnnualRevenue, Industry
FROM Account
WITH SECURITY_ENFORCED
ORDER BY Name
]; 
*/

}
}

===========================================

After putting it as requested in the challenge do not deploy to org the error.
Am I doing something wrong in the code?
Hi all, I am working on the Handle Server Error part in Trailhead as part of the Lightning Web Components and Salesforce Data Module

https://trailhead.salesforce.com/en/content/learn/modules/lightning-web-components-and-salesforce-data/handle-server-errors?trail_id=build-lightning-web-components

I am attempting to allow for error handling and write my code as follows

ContactList.js
import { LightningElement, wire } from 'lwc';
import {
    reduceErrors
} from 'c/ldsUtils';
import getContactList from '@salesforce/apex/ContactController.getContactList';

export default class ContactList extends LightningElement {
    @wire(getContactList) contacts;

    handleSelect(event) {
        // 1. Prevent default behavior of anchor tag click which is to navigate to the href url
        event.preventDefault();
        // 2. Create a custom event that bubbles. Read about event best practices at http://developer.salesforce.com/docs/component-library/documentation/lwc/lwc.events_best_practices
        const selectEvent = new CustomEvent('contactselect', {
            detail: { contactId: event.currentTarget.dataset.contactId }
        });
        // 3. Fire the custom event
        this.dispatchEvent(selectEvent);
    }
    get errors() {
        return (this.accounts.error) ?
            reduceErrors(this.accounts.error) : [];
    }
}



contactList.html
<template>
    <template if:true={contacts.data}>
        <template if:true={errors}>
            <p>{errors}</p>
        </template>
        <template for:each={contacts.data} for:item="contact">
            <a
                href="#"
                key={contact.Id}
                data-contact-id={contact.Id}
                onclick={handleSelect}
            >
                <lightning-layout>
                    <lightning-layout-item>
                        <img src={contact.Picture__c} alt="Profile photo" />
                    </lightning-layout-item>
                    <lightning-layout-item padding="horizontal-small">
                        <p>{contact.Name}</p>
                    </lightning-layout-item>
                </lightning-layout>
            </a>
        </template>
    </template>
</template>

ContactController.cls
public with sharing class ContactController {
    @AuraEnabled(cacheable=true)
    public static List<Contact> getContactList() {
        throw new AuraHandledException('Forced error');
        /*return [
            SELECT Id, Name, Title, Phone, Email, Picture__c
            FROM Contact
            WHERE Picture__c != null
            WITH SECURITY_ENFORCED
            LIMIT 10
        ];*/
    }

    @AuraEnabled(cacheable=true)
    public static List<Contact> findContacts(String searchKey) {
        String key = '%' + searchKey + '%';
        return [
            SELECT Id, Name, Title, Phone, Email, Picture__c
            FROM Contact
            WHERE Name LIKE :key AND Picture__c != null
            WITH SECURITY_ENFORCED
            LIMIT 10
        ];
    }

    @AuraEnabled(cacheable=true)
    public static Contact getSingleContact() {
        return [
            SELECT Id, Name, Title, Phone, Email, Picture__c
            FROM Contact
            WITH SECURITY_ENFORCED
            LIMIT 1
        ];
    }
}




But I get this error We can’t find 'reduceErrors' imported into contactList.js. Any steps I need to take here.