• Rafael Franco Moreno 24
  • NEWBIE
  • 30 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 4
    Replies
how can apply CSS on LWC component?

I want to hide the default save and cancel buttons
User-added image
with css but I  get this error: 

LWC1503: Parsing error: /home/sfdc/tools/lwc/2.2.9-234.6/cases.js: Only one default export allowed per module. (31:0) (31:0)

User-added imageI don´t know very well the way to hide that buttons with css, or How can I do it?
how can I close cases selected in an LWC? I need to close cases if they don´t have a Reason for closure(custom field), I don´t find anything of code, any idea? I'm newbie

User-added image

this is my html:

<template>
        <lightning-card title="Inline Edit With Lightning Datatable in LWC">
            <template if:true={cases.data}>
                <lightning-datatable key-field="Id"
                                     data={cases.data}
                                     columns={columns}
                                     onsave={handleSave}
                                     draft-values={saveDraftValues}                                                                show-row-number-column
                                     onrowselection={getSelectedName}>
                </lightning-datatable>
            </template>
        </lightning-card>
    </template>

this is js

import { LightningElement, wire, track } from 'lwc';
import getCases from '@salesforce/apex/getRecordDataController.getCases';
import { updateRecord } from 'lightning/uiRecordApi';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { refreshApex } from '@salesforce/apex';
// datatable columns
const columns = [
    {
        label: 'CaseNumber',
        fieldName: 'CaseNumber',
        type: 'text',
    }, {
        label: 'Subject',
        fieldName: 'Subject',
        type: 'text',
        editable: true,
    }, {
        label: 'Status',
        fieldName: 'Status',
        type: 'text',
        editable: true,
    }, {
        label: 'reason_for_closure__c',
        fieldName: 'reason_for_closure__c',
        type: 'phone',
        editable: true
    }
];
export default class InlineEditTable extends LightningElement {
    columns = columns;
    @track cases;
    saveDraftValues = [];
    @wire(getCases)
    cons(result) {
        this.cases = result;
        if (result.error) {
            this.cases = undefined;
        }
    };
    getSelectedName(event) {
     const selectedRows = event.detail.selectedRows;
     // Display that fieldName of the selected rows
     for (let i = 0; i < selectedRows.length; i++){
         console.log("You selected: " + selectedRows[i].CaseNumber);
     }
 }
    handleSave(event) {
        this.saveDraftValues = event.detail.draftValues;
        const recordInputs = this.saveDraftValues.slice().map(draft => {
            const fields = Object.assign({}, draft);
            return { fields };
        });
        // Updateing the records using the UiRecordAPi
        const promises = recordInputs.map(recordInput => updateRecord(recordInput));
        Promise.all(promises).then(res => {
            this.dispatchEvent(
                new ShowToastEvent({
                    title: 'Success',
                    message: 'Records Updated Successfully!!',
                    variant: 'success'
                })
            );
            this.saveDraftValues = [];
            return this.refresh();
        }).catch(error => {
            this.dispatchEvent(
                new ShowToastEvent({
                    title: 'Error',
                    message: 'An Error Occured!!',
                    variant: 'error'
                })
            );
        }).finally(() => {
            this.saveDraftValues = [];
        });
    }
    // This function is used to refresh the table once data updated
    async refresh() {
        await refreshApex(this.cases);
    }
}

this is the class:

public with sharing class getRecordDataController {
    //@AuraEnabled is annotation enables LWC to access below apex method
    //(cacheable=true) is for caching the data on client side storage without
      //waiting for server trips. Which imporves the performance
    @AuraEnabled(cacheable=true)
     public static List<Case> getCases() {
     return [SELECT CaseNumber, Subject, Status, reason_for_closure__c FROM Case WHERE Status = 'New'];
     }
   }
I have this error when save text:


Insert failed. First exception on row 0 with id 0035f000008gFMYAA2; first error: INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id]
Error is in expression '{!save}' in component <apex:commandButton> in page mensaje: Class.mensajeController.save: line 25, column 1
An unexpected error has occurred. Your development organization has been notified.

User-added image
<apex:page controller="mensajeController"  >
<apex:form >
 <apex:pageBlock >
 <apex:pageBlockButtons >
   <apex:commandButton value="Process Selected" action="{!processSelected}" rerender="test"/>
  </apex:pageBlockButtons>
  <apex:pageBlockTable value="{!contacts}" var="c" >
   <apex:column >
    <apex:inputCheckbox value="{!c.selected}"/>
   </apex:column>
    <apex:column value="{!c.con.Name}" />
    <apex:column value="{!c.con.Email}" />
    <apex:column value="{!c.con.Phone}" />
  </apex:pageBlockTable>
 </apex:pageBlock>
    <apex:pageBlock >
        <!--<p>Current description: {!mensajeContenido}</p>-->
        <p>Current description: {!oMessageDescription}</p>
        <p>Change description to:</p> 
        <!--<apex:inputTextarea id="newDesc" value="{!mensajeContenido}"/><p/>-->
        <apex:inputTextarea id="newDesc" value="{!oMessageDescription}"/><p/>
        
        <apex:commandButton value="Save" action="{!save}"/>
    </apex:pageBlock>
 <apex:pageBlock id="test">
  Total No of Selected Records :<apex:outputText value="{!value }"/>
  <apex:pageBlockTable value="{!SelectedContacts}" var="c" >
    <apex:column value="{!c.Name}" />
    <apex:column value="{!c.Email}" />
    <apex:column value="{!c.Phone}" />
  </apex:pageBlockTable>
 </apex:pageBlock>
 </apex:form>
</apex:page>
User-added image
I’m saving a text in a vf
but don’t save that text

I have to do this: 
 enter a description of the message and finally be able to save

 when saving what the controller must do is create a message object, with the description that we have entered, for each of the selected accounts
why I got this message?

Unknown property 'mensajeController.mensajeContenido'

this the vf page

<apex:page controller="mensajeController"  >
<apex:form >
 <apex:pageBlock >
 <apex:pageBlockButtons >
   <apex:commandButton value="Process Selected" action="{!processSelected}" rerender="test"/>
  </apex:pageBlockButtons>
  <apex:pageBlockTable value="{!contacts}" var="c" >
   <apex:column >
    <apex:inputCheckbox value="{!c.selected}"/>
   </apex:column>
    <apex:column value="{!c.con.Name}" />
    <apex:column value="{!c.con.Email}" />
    <apex:column value="{!c.con.Phone}" />
  </apex:pageBlockTable>
 </apex:pageBlock>
    <apex:pageBlock>
        <p>Current description: {!mensajeContenido}</p>
        <p>Change description to:</p> 
        <apex:inputTextarea id="newDesc" value="{!mensajeContenido}"/><p/>
        <apex:commandButton value="Save" action="{!save}"/>
    </apex:pageBlock>
 <apex:pageBlock id="test">
  Total No of Selected Records :<apex:outputText value="{!value }"/>
  <apex:pageBlockTable value="{!SelectedContacts}" var="c" >
    <apex:column value="{!c.Name}" />
    <apex:column value="{!c.Email}" />
    <apex:column value="{!c.Phone}" />
  </apex:pageBlockTable>
 </apex:pageBlock>
 </apex:form>
</apex:page>

this is the controller

public class mensajeController {
    public List<cContact> contactList {get; set;}
    public List<Contact> selectedContacts{get;set;}
    public Integer value {get;set;}
    public List<cContact> getContacts() {
        if(contactList == null) {
            contactList = new List<cContact>();
            for(Contact c : [select Id, Name, Email, Phone from Contact]) {
            contactList.add(new cContact(c));
            }
        }
    return contactList;
}
public PageReference processSelected() {
    selectedContacts = new List<Contact>();
    for(cContact cCon : getContacts()) {
        if(cCon.selected == true) {
        selectedContacts.add(cCon.con);
        }
    }
    value = selectedContacts.size();
    System.debug('printingtcontc'+selectedContacts.size());
    return null;
}
public List<Contact> getSelectedContacts(){
    System.debug('printingtcontc inside get'+selectedContacts.size());
    if(selectedContacts.size()>0)
       return selectedContacts;
    else return null;
}
public class cContact {
    public Contact con {get; set;}
    public Boolean selected {get; set;}
    public cContact(Contact c) {
    con = c;
    selected = false;
    }
}
    public class messageDescription {
        public string mensajeContenido {get; set;}
    }
}
 
why I get this error? I think description example4 is not inserted but why? this is the method:

@IsTest
  static void updateLeadsAndTasksTest(){      
    //update lead
    Lead newLead = Build.aLead()
    .withFirstName('rafa3')
    .withLastName('franco3')
    .withDescripcionPersonalizada('description example3')
    .withTextoAuxiliar('aux text3')
    .build();  
    insert newLead;    
    newLead.FirstName = 'rafa4';
    newLead.LastName = 'franco4';
    newLead.Descripcion_personalizada__c = 'description example4';
    newLead.Texto_auxiliar__c = 'aux text4';    
    Test.startTest();
    update newLead;
    Test.stopTest();
    List<Task> tasks = [
        SELECT WhoId, Descripcion_personalizada__c, Texto_auxiliar__c
        FROM Task
        WHERE WhoId = :newLead.id];
        for (Task task : tasks) {
          system.debug(tasks);
          system.debug('tasks');
        }
       // List<lead> leadQuery =[SELECT Descripcion_personalizada__c FROM Lead WHERE ]
    System.assertEquals(newLead.Descripcion_personalizada__c = 'description example4' ,  String.valueOf(tasks.get(0).Descripcion_personalizada__c),'text');
    System.assertEquals(newLead.Texto_auxiliar__c = 'aux text4' ,  String.valueOf(tasks.get(0)),'text');
    //System.assertEquals(expected, actual, msg)
  }
}

I am using TDD


User-added image
I have this error when I deploy the test but I don´t know why
error on apex tdd code
this my test:

@IsTest
public with sharing class LeadTaskTest {
    @IsTest
      static void createLeadsAndTasksTest(){
         
        //create new lead
        Lead newLead = Build.aLead()
        .withFirstName('rafa2')
        .withLastName('franco2')
        .withDescripcionPersonalizada('description example2')
        .withTextoAuxiliar('aux text2')
        .build();    
           
        Task newTask = Build.aTask()
        .withDescripcionPersonalizada(newLead.Descripcion_Personalizada__c)
        .withTextoAuxiliar(newLead.Texto_Auxiliar__c)
        .withWhoId(newLead);
    Test.startTest();
    insert newLead;
    insert newTask;
    Test.stopTest();
 
    List<Task> tasks = [
        SELECT WhoId, Descripcion_personalizada__c, Texto_auxiliar__c
         FROM Task
         WHERE WhoId = :newLead.id];
    System.assertEquals(1,  tasks.size(),'text');
   
  }
}

this is my handler:

public with sharing class LeadTaskHandler {
   
    public createAndInsertTaskAssociatedLeadHandler(List<Lead> leadList) {
        List<task> listTask = new List<task>();
        for (Lead lead : leadList) {
            /*create a task associated with the lead with fields created
            *Description_Personalized and Text_Auxiliar__c with lead info
            */
            Task newTask = new Task(
                Descripcion_Personalizada__c = lead.Descripcion_Personalizada__c,
                Texto_Auxiliar__c = lead.Texto_Auxiliar__c,
                WhoId = lead.id
            );
           
                     
            listTask.add(newTask);
        }
        insert listTask;
       
    }
}

my trigger: 

trigger LeadTrigger on Lead (before insert, before update, after insert) {
    if (Trigger.isBefore) {
        if (Trigger.isInsert) {
            LeadHandler.leadInsertHandler(Trigger.new);
        }
    }
    if (Trigger.isAfter) {
        if (Trigger.isInsert) {
            LeadTaskHandler.createAndInsertTaskAssociatedLeadHandler(Trigger.new);
        }
    }
}

and my build:

//Generated by BuildGenerator v1.7
@IsTest global class Build {
    /*------------------------------------------------------------------------
                 LeadBuilderStart
    ------------------------------------------------------------------------*/
     public class LeadBuilder {
        private Lead obj = new Lead(LastName = 'STRING',
            Company = 'STRING',
            Status = Lead.Status.getDescribe().getPickListValues().get(0).getValue()
        );
        public LeadBuilder withLastName(String value) {
             obj.LastName = value;
             return this;
        }
        public LeadBuilder withFirstName(String value) {
             obj.FirstName = value;
             return this;
        }
        public LeadBuilder withTextoAuxiliar(String value) {
             obj.Texto_Auxiliar__c = value;
             return this;
        }
        public LeadBuilder withDescripcionPersonalizada(String value) {
             obj.Descripcion_Personalizada__c = value;
             return this;
        }
         public Lead build() {
             return obj;
        }
    }
    public static LeadBuilder aLead() { return new LeadBuilder(); }
    /*------------------------------------------------------------------------
                 LeadBuilderEnd
    ------------------------------------------------------------------------*/
    /*------------------------------------------------------------------------
                 TaskBuilderStart
    ------------------------------------------------------------------------*/
     public class TaskBuilder {
        private Task obj = new Task(Status = 'Not Started',
            Priority = 'High'
        );
        public TaskBuilder withWhoId(Contact value) {
             obj.WhoId = value.Id;
             return this;
        }
        public TaskBuilder withWhoId(Lead value) {
             obj.WhoId = value.Id;
             return this;
        }
        public TaskBuilder withDescripcionPersonalizada(String value) {
             obj.Descripcion_Personalizada__c = value;
             return this;
        }
        public TaskBuilder withTextoAuxiliar(String value) {
             obj.Texto_Auxiliar__c = value;
             return this;
        }
         public Task build() {
             return obj;
        }
    }
    public static TaskBuilder aTask() { return new TaskBuilder(); }
    /*------------------------------------------------------------------------
                 TaskBuilderEnd
    ------------------------------------------------------------------------*/
 
}
how can I close cases selected in an LWC? I need to close cases if they don´t have a Reason for closure(custom field), I don´t find anything of code, any idea? I'm newbie

User-added image

this is my html:

<template>
        <lightning-card title="Inline Edit With Lightning Datatable in LWC">
            <template if:true={cases.data}>
                <lightning-datatable key-field="Id"
                                     data={cases.data}
                                     columns={columns}
                                     onsave={handleSave}
                                     draft-values={saveDraftValues}                                                                show-row-number-column
                                     onrowselection={getSelectedName}>
                </lightning-datatable>
            </template>
        </lightning-card>
    </template>

this is js

import { LightningElement, wire, track } from 'lwc';
import getCases from '@salesforce/apex/getRecordDataController.getCases';
import { updateRecord } from 'lightning/uiRecordApi';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { refreshApex } from '@salesforce/apex';
// datatable columns
const columns = [
    {
        label: 'CaseNumber',
        fieldName: 'CaseNumber',
        type: 'text',
    }, {
        label: 'Subject',
        fieldName: 'Subject',
        type: 'text',
        editable: true,
    }, {
        label: 'Status',
        fieldName: 'Status',
        type: 'text',
        editable: true,
    }, {
        label: 'reason_for_closure__c',
        fieldName: 'reason_for_closure__c',
        type: 'phone',
        editable: true
    }
];
export default class InlineEditTable extends LightningElement {
    columns = columns;
    @track cases;
    saveDraftValues = [];
    @wire(getCases)
    cons(result) {
        this.cases = result;
        if (result.error) {
            this.cases = undefined;
        }
    };
    getSelectedName(event) {
     const selectedRows = event.detail.selectedRows;
     // Display that fieldName of the selected rows
     for (let i = 0; i < selectedRows.length; i++){
         console.log("You selected: " + selectedRows[i].CaseNumber);
     }
 }
    handleSave(event) {
        this.saveDraftValues = event.detail.draftValues;
        const recordInputs = this.saveDraftValues.slice().map(draft => {
            const fields = Object.assign({}, draft);
            return { fields };
        });
        // Updateing the records using the UiRecordAPi
        const promises = recordInputs.map(recordInput => updateRecord(recordInput));
        Promise.all(promises).then(res => {
            this.dispatchEvent(
                new ShowToastEvent({
                    title: 'Success',
                    message: 'Records Updated Successfully!!',
                    variant: 'success'
                })
            );
            this.saveDraftValues = [];
            return this.refresh();
        }).catch(error => {
            this.dispatchEvent(
                new ShowToastEvent({
                    title: 'Error',
                    message: 'An Error Occured!!',
                    variant: 'error'
                })
            );
        }).finally(() => {
            this.saveDraftValues = [];
        });
    }
    // This function is used to refresh the table once data updated
    async refresh() {
        await refreshApex(this.cases);
    }
}

this is the class:

public with sharing class getRecordDataController {
    //@AuraEnabled is annotation enables LWC to access below apex method
    //(cacheable=true) is for caching the data on client side storage without
      //waiting for server trips. Which imporves the performance
    @AuraEnabled(cacheable=true)
     public static List<Case> getCases() {
     return [SELECT CaseNumber, Subject, Status, reason_for_closure__c FROM Case WHERE Status = 'New'];
     }
   }
I have this error when save text:


Insert failed. First exception on row 0 with id 0035f000008gFMYAA2; first error: INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id]
Error is in expression '{!save}' in component <apex:commandButton> in page mensaje: Class.mensajeController.save: line 25, column 1
An unexpected error has occurred. Your development organization has been notified.

User-added image
<apex:page controller="mensajeController"  >
<apex:form >
 <apex:pageBlock >
 <apex:pageBlockButtons >
   <apex:commandButton value="Process Selected" action="{!processSelected}" rerender="test"/>
  </apex:pageBlockButtons>
  <apex:pageBlockTable value="{!contacts}" var="c" >
   <apex:column >
    <apex:inputCheckbox value="{!c.selected}"/>
   </apex:column>
    <apex:column value="{!c.con.Name}" />
    <apex:column value="{!c.con.Email}" />
    <apex:column value="{!c.con.Phone}" />
  </apex:pageBlockTable>
 </apex:pageBlock>
    <apex:pageBlock >
        <!--<p>Current description: {!mensajeContenido}</p>-->
        <p>Current description: {!oMessageDescription}</p>
        <p>Change description to:</p> 
        <!--<apex:inputTextarea id="newDesc" value="{!mensajeContenido}"/><p/>-->
        <apex:inputTextarea id="newDesc" value="{!oMessageDescription}"/><p/>
        
        <apex:commandButton value="Save" action="{!save}"/>
    </apex:pageBlock>
 <apex:pageBlock id="test">
  Total No of Selected Records :<apex:outputText value="{!value }"/>
  <apex:pageBlockTable value="{!SelectedContacts}" var="c" >
    <apex:column value="{!c.Name}" />
    <apex:column value="{!c.Email}" />
    <apex:column value="{!c.Phone}" />
  </apex:pageBlockTable>
 </apex:pageBlock>
 </apex:form>
</apex:page>
User-added image
I’m saving a text in a vf
but don’t save that text

I have to do this: 
 enter a description of the message and finally be able to save

 when saving what the controller must do is create a message object, with the description that we have entered, for each of the selected accounts
why I got this message?

Unknown property 'mensajeController.mensajeContenido'

this the vf page

<apex:page controller="mensajeController"  >
<apex:form >
 <apex:pageBlock >
 <apex:pageBlockButtons >
   <apex:commandButton value="Process Selected" action="{!processSelected}" rerender="test"/>
  </apex:pageBlockButtons>
  <apex:pageBlockTable value="{!contacts}" var="c" >
   <apex:column >
    <apex:inputCheckbox value="{!c.selected}"/>
   </apex:column>
    <apex:column value="{!c.con.Name}" />
    <apex:column value="{!c.con.Email}" />
    <apex:column value="{!c.con.Phone}" />
  </apex:pageBlockTable>
 </apex:pageBlock>
    <apex:pageBlock>
        <p>Current description: {!mensajeContenido}</p>
        <p>Change description to:</p> 
        <apex:inputTextarea id="newDesc" value="{!mensajeContenido}"/><p/>
        <apex:commandButton value="Save" action="{!save}"/>
    </apex:pageBlock>
 <apex:pageBlock id="test">
  Total No of Selected Records :<apex:outputText value="{!value }"/>
  <apex:pageBlockTable value="{!SelectedContacts}" var="c" >
    <apex:column value="{!c.Name}" />
    <apex:column value="{!c.Email}" />
    <apex:column value="{!c.Phone}" />
  </apex:pageBlockTable>
 </apex:pageBlock>
 </apex:form>
</apex:page>

this is the controller

public class mensajeController {
    public List<cContact> contactList {get; set;}
    public List<Contact> selectedContacts{get;set;}
    public Integer value {get;set;}
    public List<cContact> getContacts() {
        if(contactList == null) {
            contactList = new List<cContact>();
            for(Contact c : [select Id, Name, Email, Phone from Contact]) {
            contactList.add(new cContact(c));
            }
        }
    return contactList;
}
public PageReference processSelected() {
    selectedContacts = new List<Contact>();
    for(cContact cCon : getContacts()) {
        if(cCon.selected == true) {
        selectedContacts.add(cCon.con);
        }
    }
    value = selectedContacts.size();
    System.debug('printingtcontc'+selectedContacts.size());
    return null;
}
public List<Contact> getSelectedContacts(){
    System.debug('printingtcontc inside get'+selectedContacts.size());
    if(selectedContacts.size()>0)
       return selectedContacts;
    else return null;
}
public class cContact {
    public Contact con {get; set;}
    public Boolean selected {get; set;}
    public cContact(Contact c) {
    con = c;
    selected = false;
    }
}
    public class messageDescription {
        public string mensajeContenido {get; set;}
    }
}
 
why I get this error? I think description example4 is not inserted but why? this is the method:

@IsTest
  static void updateLeadsAndTasksTest(){      
    //update lead
    Lead newLead = Build.aLead()
    .withFirstName('rafa3')
    .withLastName('franco3')
    .withDescripcionPersonalizada('description example3')
    .withTextoAuxiliar('aux text3')
    .build();  
    insert newLead;    
    newLead.FirstName = 'rafa4';
    newLead.LastName = 'franco4';
    newLead.Descripcion_personalizada__c = 'description example4';
    newLead.Texto_auxiliar__c = 'aux text4';    
    Test.startTest();
    update newLead;
    Test.stopTest();
    List<Task> tasks = [
        SELECT WhoId, Descripcion_personalizada__c, Texto_auxiliar__c
        FROM Task
        WHERE WhoId = :newLead.id];
        for (Task task : tasks) {
          system.debug(tasks);
          system.debug('tasks');
        }
       // List<lead> leadQuery =[SELECT Descripcion_personalizada__c FROM Lead WHERE ]
    System.assertEquals(newLead.Descripcion_personalizada__c = 'description example4' ,  String.valueOf(tasks.get(0).Descripcion_personalizada__c),'text');
    System.assertEquals(newLead.Texto_auxiliar__c = 'aux text4' ,  String.valueOf(tasks.get(0)),'text');
    //System.assertEquals(expected, actual, msg)
  }
}

I am using TDD


User-added image