• Kyle Havelka
  • NEWBIE
  • 10 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 1
    Replies
Hi All,

Firstly, I wanted to indicate that I have poured over the LWC Recipes repo to find this, and I can't.

I am trying to get test coverage on a Lightning Web Component. The component has two Sub components. One is a custom component the other is a base lightning-datatable. My component ties into the data table's onrowaction event using a handler called handleRowAction (see below).
<template>
  <c-move-management-form
    action={moveAction}
    goal-type-id={selectedMoveGoalTypeId}
    goal-id={selectedMoveGoalId}
    move={selectedMove}
    onmoveformclosed={handleMoveFormClosed}
    onmovesaved={handleMoveChangeCommitted}
    record-id={selectedMoveId}
    show={displayRecordManager}
  >
  </c-move-management-form>
  <lightning-datatable
    key-field="MoveId"
    data={data}
    columns={columns}
    onrowaction={handleRowAction}
  >
  </lightning-datatable>
</template>
The handler uses a switch statement to determine the action type, which is just edit for now. Based upon the action it calls antoher function (hanlder and helper function below) to do something (in the case of edit, it will show a custom modal form).
handleRowAction(event) {
    const actionName = event.detail.action.name;
    var row = event.detail.row;
    switch (actionName) {
      case "edit":
        this.handleEditMoveClicked(row);
        break;

      default:
        break;
    }
  }

  handleEditMoveClicked(row) {
    if (row) {
      this.selectedMoveId = row.MoveId;
      this.selectedMove = row;
      this.displayRecordManager = true;
    }
  }
In my test class, I am trying to hit the handleRowAction(event) function, which will ultimately call the handleEditMoveClicked(row) function.

To do this, I am using a dispatching a custom event on the lightning datatable element, in the detail I am putting in the action type so that it will be handed off to the handleEditMoveClicked function (see below).
 
it("displays c-move-management-form when rowaction edit event raised", () => {
    const rowActionEvent = new CustomEvent("rowaction", {
      detail: { action: { name: "edit" } }
    });

    const element = createElement("c-contact-record-detail-embed", {
      is: ContactRecordDetailEmbed
    });
    document.body.appendChild(element);

    const dataTable = element.shadowRoot.querySelector("lightning-datatable");
    dataTable.dispatchEvent(rowActionEvent);
  });
This does sucessfully call the handleRowAction method, but it will obviously not be properly handled by the handleEditMoveClicked because the row is undefined. I tried to add the row informaiton to the event, but then the handleRowAction method is never called (example test code below new code highlighted for clarity).
it("displays c-move-management-form when rowaction edit event raised", () => {
    const rowActionEvent = new CustomEvent("rowaction", {
      detail: {
        action: { name: "edit" },
        row: { MoveId: "123" }
      }
    });

    const element = createElement("c-contact-record-detail-embed", {
      is: ContactRecordDetailEmbed
    });
    document.body.appendChild(element);

    const dataTable = element.shadowRoot.querySelector("lightning-datatable");
    dataTable.dispatchEvent(rowActionEvent);
  });
What am I doing wrong? Does anyone have experience with something like this?
Does anyone know what happened to the Local Development Server for LWC? I used it for a few days, it was definetly buggy, but was good for quick wireframes.

I switched to a different PC, and it appears the package is gone, I tried sfdx plugins:install lwc-dev-server and it said plugin not found.
Hi All,

Let me preface this with a disclaimer. I am fairly new to SalesForce development. But I have 11 years experience as a developer.

I am working on a LWC that calls an Apex controller.

The Apex controller runs a fairly simple SOQL query against a custom object Move_Type__c. It has a master detail relationship with another Custom object Move_Goal_Type__c (see below)

Move_Type & Move_Goal_Type

Here is the query: 
[SELECT Name, Id
FROM pursue02__Move_Type__c
WHERE pursue02__Move_Goal_Type__r.Id = :movegoalTypeId ]
The variable comes into the controller (MoveTypeController) as an Id through a method getMoveTypesByMoveGoalTypeId which is decorated with @AuraEnabled(cacheable=true)

When I execute anonynmous, it works as expected, I get a list of Move_Type__c records with the Name and Id.

When the LWC calls it, it returns an empty array. Now I have debugged the method System.debug(movegoalTypeId) and it shows the correct value. And I assigned the SOQL results to a variable and output that as well, it shows values in the debug logs.

I have also checked the network traffic via chrome developer tools and it's sending the value as expected:
message: {
    "actions": [
        {
            "id": "815;a",
            "descriptor": "aura://ApexActionController/ACTION$execute",
            "callingDescriptor": "UNKNOWN",
            "params": {
                "namespace": "pursue02",
                "classname": "MoveTypeController",
                "method": "getMoveTypesByMoveGoalTypeId",
                "params": {
                    "goalTypeId": "a013k00000aWHa6AAG"
                },
                "cacheable": true,
                "isContinuation": false
            }
        }
    ]
}
But as I said it returns an empty array:
"actions": [
        {
            "id": "815;a",
            "state": "SUCCESS",
            "returnValue": {
                "returnValue": [],
                "cacheable": true
            },
            "error": []
        }
    ],
We have checked the permissions on both Move_Type__c and Move_Goal_Type__c, and they all appear to be correct.

Any one know what we are doing wrong? I'm scratching my head on this one.

Any help would be greatly appreciated!

 
Hi All,

Let me preface this with a disclaimer. I am fairly new to SalesForce development. But I have 11 years experience as a developer.

I am working on a LWC that calls an Apex controller.

The Apex controller runs a fairly simple SOQL query against a custom object Move_Type__c. It has a master detail relationship with another Custom object Move_Goal_Type__c (see below)

Move_Type & Move_Goal_Type

Here is the query: 
[SELECT Name, Id
FROM pursue02__Move_Type__c
WHERE pursue02__Move_Goal_Type__r.Id = :movegoalTypeId ]
The variable comes into the controller (MoveTypeController) as an Id through a method getMoveTypesByMoveGoalTypeId which is decorated with @AuraEnabled(cacheable=true)

When I execute anonynmous, it works as expected, I get a list of Move_Type__c records with the Name and Id.

When the LWC calls it, it returns an empty array. Now I have debugged the method System.debug(movegoalTypeId) and it shows the correct value. And I assigned the SOQL results to a variable and output that as well, it shows values in the debug logs.

I have also checked the network traffic via chrome developer tools and it's sending the value as expected:
message: {
    "actions": [
        {
            "id": "815;a",
            "descriptor": "aura://ApexActionController/ACTION$execute",
            "callingDescriptor": "UNKNOWN",
            "params": {
                "namespace": "pursue02",
                "classname": "MoveTypeController",
                "method": "getMoveTypesByMoveGoalTypeId",
                "params": {
                    "goalTypeId": "a013k00000aWHa6AAG"
                },
                "cacheable": true,
                "isContinuation": false
            }
        }
    ]
}
But as I said it returns an empty array:
"actions": [
        {
            "id": "815;a",
            "state": "SUCCESS",
            "returnValue": {
                "returnValue": [],
                "cacheable": true
            },
            "error": []
        }
    ],
We have checked the permissions on both Move_Type__c and Move_Goal_Type__c, and they all appear to be correct.

Any one know what we are doing wrong? I'm scratching my head on this one.

Any help would be greatly appreciated!

 
Hi All,

Let me preface this with a disclaimer. I am fairly new to SalesForce development. But I have 11 years experience as a developer.

I am working on a LWC that calls an Apex controller.

The Apex controller runs a fairly simple SOQL query against a custom object Move_Type__c. It has a master detail relationship with another Custom object Move_Goal_Type__c (see below)

Move_Type & Move_Goal_Type

Here is the query: 
[SELECT Name, Id
FROM pursue02__Move_Type__c
WHERE pursue02__Move_Goal_Type__r.Id = :movegoalTypeId ]
The variable comes into the controller (MoveTypeController) as an Id through a method getMoveTypesByMoveGoalTypeId which is decorated with @AuraEnabled(cacheable=true)

When I execute anonynmous, it works as expected, I get a list of Move_Type__c records with the Name and Id.

When the LWC calls it, it returns an empty array. Now I have debugged the method System.debug(movegoalTypeId) and it shows the correct value. And I assigned the SOQL results to a variable and output that as well, it shows values in the debug logs.

I have also checked the network traffic via chrome developer tools and it's sending the value as expected:
message: {
    "actions": [
        {
            "id": "815;a",
            "descriptor": "aura://ApexActionController/ACTION$execute",
            "callingDescriptor": "UNKNOWN",
            "params": {
                "namespace": "pursue02",
                "classname": "MoveTypeController",
                "method": "getMoveTypesByMoveGoalTypeId",
                "params": {
                    "goalTypeId": "a013k00000aWHa6AAG"
                },
                "cacheable": true,
                "isContinuation": false
            }
        }
    ]
}
But as I said it returns an empty array:
"actions": [
        {
            "id": "815;a",
            "state": "SUCCESS",
            "returnValue": {
                "returnValue": [],
                "cacheable": true
            },
            "error": []
        }
    ],
We have checked the permissions on both Move_Type__c and Move_Goal_Type__c, and they all appear to be correct.

Any one know what we are doing wrong? I'm scratching my head on this one.

Any help would be greatly appreciated!