1

JavaScript handler handleStatusChange() yields a 500 error:

An internal server error has occurred\nError ID: 1567951226-566936 (-1434965262)"

Any ideas on what I might be doing wrong? Is it because I'm not using @wire or @connectedCallback? Do I need to use @track or @future?

The same Apex code works in the developer console's Execute Anonymous window without any issue.

Apex

  @AuraEnabled
  public static void updateResponseStatus(String checklistId, String checkpointId, String status) {
    System.debug('Start updateResponseStatus');
    try {
      Project_Checkpoint_Response__c r = new Project_Checkpoint_Response__c();
      r.Project_Checklist__c = String.valueOf(checklistId);
      r.Project_Checklist_Checkpoint__c = String.valueOf(checkpointId);
      r.Status__c = String.valueOf(status);
      r.Note__c = 'Test';
      insert r;
    } catch(Exception e) {
      System.debug('An unexpected error has occurred: ' + e.getMessage());
    }
  }

JavaScript

async handleStatusChange(event) {
  const checkpointId = event.target.name;
  const status = event.detail.value;

  updateResponseStatus(this.recordId, checkpointId, status).then((response) => {
    console.log('response', response);
  }).catch((error) => { 
    console.log('error', error);
  });
}

Markup

<lightning-radio-group
  name={chkpt.id}
  label="Status"
  options={options}
  required
  value={chkpt.response.status}
  onchange={handleStatusChange}
  type="button">
</lightning-radio-group>

1 Answer 1

2

You normally need to exactly match the Apex names used in the Apex passing a single JavaScript object rather than relying on position so longhand:

updateResponseStatus({
    checklistId: this.recordId,
    checkpointId: checkpointId
    status: status
})...

or shorthand if you make sure the JavaScript values have matching names:

const checklistId = this.recordId;
updateResponseStatus({ checklistId, checkpointId, status })...
2
  • is there any benefit of shorthand over longhand or vice versa. I personally always use long hand
    – Elijah
    Jun 30, 2022 at 17:33
  • It depends on who's going to read it. Some people are not familiar with the ES6 shorthand Jun 30, 2022 at 22:23

You must log in to answer this question.

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