• Josephine But
  • NEWBIE
  • 20 Points
  • Member since 2023

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 2
    Replies
Hi,
  I want to add a quick action button for my component(lwc) on the list view. And in my js-meta.xml, I added the following :

<targets>
<target>lightning__AppPage</target>
<target>lightning__HomePage</target>
<target>lightning__RecordPage</target>
<target>lightning_RecordAction</target>
</targets>
<targetConfigs>
<targetConfig targets="lightning_RecordAction">
<actionType>Action</actionType>
</targetConfig>
</targetConfigs>

but I got the following error message when I tried to add it to my org:
'lightning_RecordAction' target is not a valid target.

Anyone knows how to add a quick action button to the component (lwc) on the list view? Any example or reference is appreciated.

Thanks,
   Jo
Hi,
  I have the following statement I want to do  the testing, System.assertEquals('Kitchen Cabinet',stockX[0].product__c );

stockX[0].product__c is a reference( a lookup field to the product), how can I get the name of the product instead of getting the reference??

Thanks,
    Jo

Hi,
  I am new in LWC, I have a dynamic table to add and delete rows and adding a product. Besides to delete the row, I would like to delete the corresponding record as well, does anybody has idea?

MY HTML CODE :
<template>
<lightning-card title="Create & Delete Products">
<template for:each={itemList} for:item="item" for:index="index">
<lightning-record-edit-form key={item.id} object-api-name="Product2">
<lightning-messages> </lightning-messages>
<lightning-layout multiple-rows>
<lightning-layout-item size="12" small-device-size="6" medium-device-size="4" large-device-size="2"
padding="around-small">
<lightning-input-field field-name="Name" variant="label-stacked" required>
</lightning-input-field>
</lightning-layout-item>
<lightning-layout-item size="12" small-device-size="6" medium-device-size="4" large-device-size="2"
padding="around-small">
<lightning-input-field field-name="ProductCode" variant="label-stacked" required>
</lightning-input-field>
</lightning-layout-item>
<lightning-layout-item size="12" small-device-size="6" medium-device-size="4" large-device-size="2"
padding="around-small">
<lightning-input-field field-name="Quantity__c" variant="label-stacked" required>
</lightning-input-field>
</lightning-layout-item>
<lightning-layout-item size="12" small-device-size="6" medium-device-size="4" large-device-size="2"
padding="around-small">
<lightning-input-field field-name="Price__c" variant="label-stacked" required>
</lightning-input-field>
</lightning-layout-item>
<lightning-layout-item size="12" small-device-size="6" medium-device-size="4" large-device-size="2"
padding="around-small">
<div class="slds-p-top_medium">
<lightning-icon icon-name="action:new" access-key={item.id} id={index}
alternative-text="Add Row" size="small" title="Add Row" onclick={addRow}>
</lightning-icon>
<lightning-icon icon-name="action:delete" access-key={item.id} id={index}
alternative-text="Delete Row" size="small" title="Delete Row" onclick={removeRow}>
</lightning-icon>
</div>
</lightning-layout-item>
</lightning-layout>
</lightning-record-edit-form>
</template>
</br>
<lightning-layout>
<div class="slds-align_absolute-center">
<lightning-button variant="success" onclick={handleSubmit} name="submit" label="Submit">
</lightning-button>
</div>
</lightning-layout>
</lightning-card>
</template>


MY JS CODE :
import { LightningElement, track } from 'lwc';
import { NavigationMixin } from 'lightning/navigation';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
export default class CreateDeleteProducts extends LightningElement {
keyIndex = 0;
@track itemList = [
{
id: 0
}
];
addRow() {
++this.keyIndex;
var newItem = [{ id: this.keyIndex }];
this.itemList = this.itemList.concat(newItem);
}
removeRow(event) {
if (this.itemList.length >= 2) {
this.itemList = this.itemList.filter(function (element) {
return parseInt(element.id) !== parseInt(event.target.accessKey);
});
}
}
handleSubmit() {
var isVal = true;
this.template.querySelectorAll('lightning-input-field').forEach(element => {
isVal = isVal && element.reportValidity();
});
if (isVal) {
this.template.querySelectorAll('lightning-record-edit-form').forEach(element => {
element.submit();
});
this.dispatchEvent(
new ShowToastEvent({
title: 'Success',
message: 'Products created successfully',
variant: 'success',
}),
);
// Navigate to the Product home page
this[NavigationMixin.Navigate]({
type: 'standard__objectPage',
attributes: {
objectApiName: 'Product2',
actionName: 'home',
},
});
} else {
this.dispatchEvent(
new ShowToastEvent({
title: 'Error creating record',
message: 'Please enter all the required fields',
variant: 'error',
}),
);
}
}
}

Hi,
  I am new in writing LWC. Just wondering how to display related contacts that associated with an account with datatable. ANy example is appreciated.

Thanks,
    Jo
I am using lightning Data service to create a record, but doesn't work. I am new in this area, please help. After save, it gives me nothing, not even error message or alert??

createToDoRecord.cmp
==================
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global">
<!-- <aura:registerEvent name="displayRecords" type="c:displayRecords"/> -->
<aura:attribute name="ToDoTask" type="ToDo__c" default="{'sobjectType' : 'ToDo__c'}"/> <!-- <aura:attribute name="Tasks" type="List"/> -->
<aura:attribute name="recordSaveError" type="String"/>

<aura:if isTrue="{!not(empty(v.recordSaveError))}">
<div>{!v.recordSaveError}</div>
</aura:if>
<force:recordData aura:id="service" fields=
"Name,
Due_Date__c,
Reminder_Date__c,
Description__c" targetFields="{!v.ToDoTask}" targetError="{!v.recordSaveError}"
/>
<form class="slds-form--stacked slds-p-horizontal_small">
<div class="slds-box slds-theme_default">
<lightning:input name="title" label="Title" value="{!v.ToDoTask.Name}"/>
</div>
<div class="slds-box slds-theme_default">
<lightning:input name="description" label="Description" value="{!v.ToDoTask.Description__c}"/>
</div>
<div class="slds-box slds-theme_default">
<lightning:input type="date" name="due_date" label="Due Date" value="{!v.ToDoTask.Due_Date__c}"/>
</div>
<div class="slds-box slds-theme_default">
<lightning:input type="date" name="reminder_date" label="Reminder Date" value="{!v.ToDoTask.Reminder_Date__c}"/>
</div>
<lightning:layout horizontalAlign="center" class="slds-p-top_small">
<lightning:button label="submit" iconName="utility:save" iconPosition="center" onclick="{!c.onSave}"/>
</lightning:layout>
</form>

</aura:component>

createToDoRecordController.js
========================
({
onSave: function(component, event, helper){
alert("onSave");
alert(component.find("service").get());
component.find("service").saveRecord(function(saveResult){
alert("I am here");
if(saveResult.state === "SUCCESS" || saveResult.state === "DRAFT"){
alert("onSave IF SUCCESS/DRAFT");
//toast notification
var resToast = $A.get("e.force:showToast");
resToast.setParams({
"title": "Saved",
"message": "Record saved",
"type": "success"
});
resToast.fire();
helper.init(component, event, helper);
}
else if (saveResult.state === "ERROR"){
console.log("Problem Saving");
}
else if(saveResult.state === "DRAFT"){
console.log("Draft");
}
else{
alert("Other Error");
// console.log("Other Error");
}
// var eventToFire = $A.get("e.c:displayRecords");
// eventToFire.fire();
});
}
})

createToDoRecordHelper.js
=====================
({
init: function (component, event, helper) {
alert("init new task helper");
var action = component.get("c.fetchToDoTasks");
action.setCallback(this, function (response) {
var state = response.getState();
console.log(state);
// if (state === "SUCCESS") {
// component.set("v.KartTypes", response.getReturnValue());
// }
});
$A.enqueueAction(action);
}
})


 
Hi,
  I have an object appointments which have a lookup field to Hospital(Hospital__c) and I have an object Hospital which contains the names of the hospital. I want to know how many appointments in each hospital. What is the query look like?

Thanks,
    Jo
Hi,
  I have the following statement I want to do  the testing, System.assertEquals('Kitchen Cabinet',stockX[0].product__c );

stockX[0].product__c is a reference( a lookup field to the product), how can I get the name of the product instead of getting the reference??

Thanks,
    Jo
I am using lightning Data service to create a record, but doesn't work. I am new in this area, please help. After save, it gives me nothing, not even error message or alert??

createToDoRecord.cmp
==================
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global">
<!-- <aura:registerEvent name="displayRecords" type="c:displayRecords"/> -->
<aura:attribute name="ToDoTask" type="ToDo__c" default="{'sobjectType' : 'ToDo__c'}"/> <!-- <aura:attribute name="Tasks" type="List"/> -->
<aura:attribute name="recordSaveError" type="String"/>

<aura:if isTrue="{!not(empty(v.recordSaveError))}">
<div>{!v.recordSaveError}</div>
</aura:if>
<force:recordData aura:id="service" fields=
"Name,
Due_Date__c,
Reminder_Date__c,
Description__c" targetFields="{!v.ToDoTask}" targetError="{!v.recordSaveError}"
/>
<form class="slds-form--stacked slds-p-horizontal_small">
<div class="slds-box slds-theme_default">
<lightning:input name="title" label="Title" value="{!v.ToDoTask.Name}"/>
</div>
<div class="slds-box slds-theme_default">
<lightning:input name="description" label="Description" value="{!v.ToDoTask.Description__c}"/>
</div>
<div class="slds-box slds-theme_default">
<lightning:input type="date" name="due_date" label="Due Date" value="{!v.ToDoTask.Due_Date__c}"/>
</div>
<div class="slds-box slds-theme_default">
<lightning:input type="date" name="reminder_date" label="Reminder Date" value="{!v.ToDoTask.Reminder_Date__c}"/>
</div>
<lightning:layout horizontalAlign="center" class="slds-p-top_small">
<lightning:button label="submit" iconName="utility:save" iconPosition="center" onclick="{!c.onSave}"/>
</lightning:layout>
</form>

</aura:component>

createToDoRecordController.js
========================
({
onSave: function(component, event, helper){
alert("onSave");
alert(component.find("service").get());
component.find("service").saveRecord(function(saveResult){
alert("I am here");
if(saveResult.state === "SUCCESS" || saveResult.state === "DRAFT"){
alert("onSave IF SUCCESS/DRAFT");
//toast notification
var resToast = $A.get("e.force:showToast");
resToast.setParams({
"title": "Saved",
"message": "Record saved",
"type": "success"
});
resToast.fire();
helper.init(component, event, helper);
}
else if (saveResult.state === "ERROR"){
console.log("Problem Saving");
}
else if(saveResult.state === "DRAFT"){
console.log("Draft");
}
else{
alert("Other Error");
// console.log("Other Error");
}
// var eventToFire = $A.get("e.c:displayRecords");
// eventToFire.fire();
});
}
})

createToDoRecordHelper.js
=====================
({
init: function (component, event, helper) {
alert("init new task helper");
var action = component.get("c.fetchToDoTasks");
action.setCallback(this, function (response) {
var state = response.getState();
console.log(state);
// if (state === "SUCCESS") {
// component.set("v.KartTypes", response.getReturnValue());
// }
});
$A.enqueueAction(action);
}
})