0

I have AuraEnabled method in a following class:

public with sharing class HistoryRecordsHandler {
@AuraEnabled
public static List<HistoryRecordWrapper> getAccountAndContactHistoryRecords(Id accId) {
    List<HistoryRecordWrapper> hrws = new List<HistoryRecordWrapper>();

    List<AccountHistory> accHis = [SELECT AccountId, CreatedById, CreatedDate, Field, DataType, IsDeleted, NewValue, OldValue FROM AccountHistory WHERE AccountId = :accId];
    List<ContactHistory> conHis = [
        SELECT ContactId, CreatedById, CreatedDate, Field, DataType, IsDeleted, NewValue, OldValue
        FROM ContactHistory
        WHERE Contact.AccountId = :accId
    ];

    for (ContactHistory conHi : conHis) {
        HistoryRecordWrapper crs = new HistoryRecordWrapper(conHi);
        hrws.add(crs);
    }

    for (AccountHistory accHi : accHis) {
        HistoryRecordWrapper hrs = new HistoryRecordWrapper(accHi);
        hrws.add(hrs);
    }

    hrws.sort();
    return hrws;
}

Once I call the method from the LWC component I am getting internal server error: b {status: 500, body: Error: An internal server error has occurred}

import { LightningElement, track } from 'lwc';
import getHistoryRecords from '@salesforce/apex/HistoryRecordsHandler.getAccountAndContactHistoryRecords';
connectedCallback() {
    getHistoryRecords('0014x00000DSDc0AAH')
        .then((listOfHistoryRecords) => {
            this.historyRecords = listOfHistoryRecords;
            console.log(this.historyRecords);
        })
        .catch((error) => console.log('error happening: ', error));
}

}

Am I missing something in the class?? When I execute this method in the developer console I am getting the correct response (account and contact history records)

1 Answer 1

2

Your parameters need to be named, even if you only have one:

getHistoryRecords({accId:'0014x00000DSDc0AAH'})

This is a problem with your JavaScript, not your class.

You must log in to answer this question.

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