• jishan roy
  • NEWBIE
  • 20 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 29
    Questions
  • 27
    Replies
hello i want to help in flow like,
Add a tab related to Account and in that Tab there are 2 picklist Options - 1- Contact, 2- Opportunity
When clicked contact then open screen for creating contact and after inserted all required fields contacts have created.
and for opportunity --same like contact
hello can anybody help to find the solution of
Data types of trigger.new i m confuse.
How to display opportunity associated all products in trigger.
Here is my code:
trigger opportunityProductCount on Product2 (after insert, after update, after delete, after undelete) {
    set<Id> setIds = new set<Id>();
    list<Opportunity> opplist= new list<Opportunity>();
    if(trigger.isafter){
        if(trigger.isinsert|| trigger.isUpdate|| trigger.isUndelete){
            for(Product2 p: trigger.new){
                setIds.add(p.OpportunityId);
            }
        }
        if(trigger.isupdate|| trigger.isdelete){
            for(Product2 po:trigger.old){
                setIds.add(po.OpportunityId);
            }
        }
    }
    List<Opportunity> oplist = [Select Id,Name,Number_of_Product__c,(select id,name from Products2)from Opportunity where Id in:setIds];
    system.debug('show products'+ oplist);
    for (Opportunity opp: oplist){
        Integer count = opp.Products2.size();
        opp.Number_of_Product__c = count;
        opplist.add(opp);
        
    }
    update opplist;

}
Can anybody help to out of this que how to associated record and count display in oppoprtunity in trigger.I just started to learn development.
how to add this apex callouts in js can anybody help me?
Here is my code:

apex class:
public class personDemoController {
    @AuraEnabled
    public static void calloutMethod(){
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        request.setEndpoint('https://lookup.binlist.net/45717360');
        request.setMethod('GET');
        HttpResponse response = http.send(request);
        String body = response.getbody();
        system.debug(body);
    }
}

js:
import { LightningElement} from 'lwc';
import calloutMethod from '@salesforce/apex/personDemoController.calloutMethod';
import { createRecord } from 'lightning/uiRecordApi';
import conMainObject from '@salesforce/schema/Contact';
import conFirstName from '@salesforce/schema/Contact.FirstName';
import conLastName from '@salesforce/schema/Contact.LastName';
import conPhone from '@salesforce/schema/Contact.Phone';
import conEmail from '@salesforce/schema/Contact.Email';
import conDescription from '@salesforce/schema/Contact.Description';
import conCard_Name__c from '@salesforce/schema/Contact.Card_Name__c';
//import conPrepaid__c from '@salesforce/schema/Contact.Prepaid__c';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { NavigationMixin } from 'lightning/navigation';
export default class IntegrateComponentLWC extends NavigationMixin(LightningElement) {
firstName = '';
lastName = '';
phoneNo= '';
emailId='';
descriptionVal='';
//prepaid__c='';
card_Name__c='';


contactChangeVal(event) {
    console.log(event.target.label);
    console.log(event.target.value);        
    if(event.target.label=='First Name'){
        this.firstName = event.target.value;
    }
    if(event.target.label=='Last Name'){
        this.lastName = event.target.value;
    }            
    if(event.target.label=='Phone'){
        this.phoneNo = event.target.value;
    }
    if(event.target.label=='Email'){
        this.emailId = event.target.value;
    }
   if(event.target.label=='Card_Name__c'){
        this.cardName = event.target.value;
    }
    if(event.target.label=='Description'){
        this.descriptionVal = event.target.value;
    }      
    // if(event.target.label=='Prepaid__c'){
    //     this.prepaid__c = event.target.value;
    // }  
    
    
}

insertContactAction(){
    console.log(this.selectedAccountId);
    const fields = {};
    fields[conFirstName.fieldApiName] = this.firstName;
    fields[conLastName.fieldApiName] = this.lastName;
    fields[conPhone.fieldApiName] = this.phoneNo;
    fields[conEmail.fieldApiName] = this.emailId;
    fields[conCard_Name__c.fieldApiName] = this.cardName;
    fields[conDescription.fieldApiName] = this.descriptionVal;
    //fields[conPrepaid__c.fieldApiName] = this.prepaid__c;
    
    
    const recordInput = { apiName: conMainObject.objectApiName, fields };
    createRecord(recordInput)
        .then(contactobj=> {
            this.contactId = contactobj.id;
            this.dispatchEvent(
                new ShowToastEvent({
                    title: 'Success',
                    message: 'Contact record has been created',
                    variant: 'success',
                }),
            );
            this[NavigationMixin.Navigate]({
                type: 'standard__recordPage',
                attributes: {
                    recordId: contactobj.id,
                    objectApiName: 'Contact',
                    actionName: 'view'
                },
            });


        })
        .catch(error => {
            this.dispatchEvent(
                new ShowToastEvent({
                    title: 'Error creating record',
                    message: error.body.message,
                    variant: 'error',
                }),
            );
        });
}
handleClick(){
    calloutMethod({}).then(resp => {
            this.pictureUrl = JSON.parse(resp).message;
    })
}
}

html:

<template>
    <lightning-card>
        <div slot="title">
          <h3> 
                <lightning-icon icon-name="standard:contact" size="small"></lightning-icon> Insert a Contact Record in LWC           
             </h3>
          </div>
      <div class="slds-grid slds-wrap">
 
          <div class="slds-p-horizontal--small slds-col slds-size_6-of-12 slds-m-bottom--medium">
              <div class="slds-form-element">
                <lightning-input label="First Name" value={firstName} onchange={contactChangeVal}></lightning-input>
              </div>
          </div>
 
          <div class="slds-p-horizontal--small slds-col slds-size_6-of-12 slds-m-bottom--medium">
            <div class="slds-form-element">
                <lightning-input label="Last Name" value={lastName} onchange={contactChangeVal}></lightning-input>
             </div>
          </div>
 
          <div class="slds-p-horizontal--small slds-col slds-size_6-of-12 slds-m-bottom--medium">
            <div class="slds-form-element">
                <lightning-input label="Phone" value={phoneNo} onchange={contactChangeVal}></lightning-input>
             </div>
          </div>
 
          <div class="slds-p-horizontal--small slds-col slds-size_6-of-12 slds-m-bottom--medium">
            <div class="slds-form-element">
                <lightning-input label="Email" value={emailId} onchange={contactChangeVal} ></lightning-input>
             </div>
          </div>
 
          <div class="slds-p-horizontal--small slds-col slds-size_6-of-12 slds-m-bottom--medium">
            <div class="slds-form-element">
                <lightning-input label="Prepaid" value={Prepaid__c} onchange={contactChangeVal} ></lightning-input>
             </div>
          </div>
 
          <div class="slds-p-horizontal--small slds-col slds-size_6-of-12 slds-m-bottom--medium">
            
            <div class="slds-form-element">               
               <lightning-input label="Description" value={descriptionVal} onchange={contactChangeVal}></lightning-input>
             </div>
          </div>
          
      </div>
     <div slot="footer">
      
      <lightning-button label="Save" variant="brand" onclick={insertContactAction}></lightning-button>        
      </div>
      <lightning-button variant="success"  label="Generate card details" onclick={handleClick}></lightning-button>
 
<br/> <br/>
    <!-- </div> -->
        </lightning-card> 
</template>
here is my code:

for(case c : lstCase){
            if(c.Latest_Comment__c==Null||c.Latest_Comment__c!=Null){
                c.Latest_Comment__c=c.Comments;
                
            }
        }


But this will work only when create a new case when update comment in that case it will not getting output.
If anybody know then please help me out of this problem
Thanks in Advance.
my requirement is when i will add comment in case feed comment then in case field which i created (latestComment) show latest comment.

here is my code: for Trigger

trigger latestCommentTrigger on Case (before insert, after update) {
    for(Case c : trigger.new) {
        if(c.Comments == Null){
            c.Comments.adderror('enter comment');
        }
        c.Comments = c.Latest_Comment__c;
        
            }
}


i didnot getting output of this code can any one help me out of this question.
here is my code i want to know how to iterate the Account contact oppoptunity product data in for loop can any one help it is urgent.

handleUploadFinished(event){
        alert("file uploaded");
        var file = event.target.files[0];
        console.log(file);
        // this.attachmentArray = [];
        // for(var i=0; i< file.length; i++){
        //     const fileName = file[i].name;
        //     console.log('fileName' + fileName);
       var reader = new FileReader();
       reader.onload = event => {
           alert('onload');
           var data=event.target.result;
             var workbook=XLS.read(data, {
                type: 'binary'
                
            });
            console.log(workbook);
            
            var XL_row_object = XLS.utils.sheet_to_row_object_array(workbook.Sheets["Account"]);
            console.log(workbook.SheetNames);
            var data = JSON.stringify(XL_row_object);
            console.log(data);
            var XL_row_object = XLS.utils.sheet_to_row_object_array(workbook.Sheets["Contact"]);
            //console.log(workbook.Sheets);
            var data = JSON.stringify(XL_row_object);
            console.log(data);
            var XL_row_object = XLS.utils.sheet_to_row_object_array(workbook.Sheets["Opportunity"]);
            //console.log(workbook.Sheets);
            var data = JSON.stringify(XL_row_object);
            console.log(data);
            var XL_row_object = XLS.utils.sheet_to_row_object_array(workbook.Sheets["Product"]);
            //console.log(workbook.Sheets);
            var data = JSON.stringify(XL_row_object);
            console.log(data);

       };
        reader.readAsBinaryString(file);
         
    }
The requirement is show the excell file in object-account in lwc.
I have to upload multiple excel sheet file in account record:
here is my code this code is for only single file upload: how to upload multiple? please help me out.

apex:

public with sharing class lwcCSVUploaderController {
    @AuraEnabled
    public static List<Account> saveFile(String base64Data) {
        String data = JSON.deserializeUntyped(base64Data).toString();
        list<Account> lstCCToInsert = new list<Account>();
        list<String> lstCSVLines = data.split('\n');
        for(Integer i = 1; i < lstCSVLines.size(); i++){
            Account acc = new Account();
            String csvLine = lstCSVLines[i];
            String prevLine = csvLine;
            Integer startIndex;
            Integer endIndex;
           
            while(csvLine.indexOf('"') > -1){
           
                if(startIndex == null){
                    startIndex = csvLine.indexOf('"');
                    csvLine = csvLine.substring(0, startIndex) + ':quotes:' + csvLine.substring(startIndex+1, csvLine.length());
                }else{
                    if(endIndex == null){
                        endIndex = csvLine.indexOf('"');
                        csvLine = csvLine.substring(0, endIndex) + ':quotes:' + csvLine.substring(endIndex+1, csvLine.length());
                    }
                }
                if(startIndex != null && endIndex != null){
                    String sub = csvLine.substring(startIndex, endIndex);
                    sub = sub.replaceAll(',', ':comma:');
                    csvLine = csvLine.substring(0, startIndex) + sub + csvLine.substring(endIndex, csvLine.length());
                    startIndex = null;
                    endIndex = null;
                }
            }
            List<String> csvRowData = new List<String>();
            for(String column : csvLine.split(',')){
                column = column.replaceAll(':quotes:', '').replaceAll(':comma:', ',');
                csvRowData.add(column);
            }
            acc.Name = csvRowData[0];
            acc.Phone = csvRowData[1];
            lstCCToInsert.add(acc);
        }
        insert lstCCToInsert;
        return [Select Name, Phone From Account Where CreatedDate>=:Date.TODAY()];
    }
}


js:

import { LightningElement, track,api } from 'lwc';
import saveFile from '@salesforce/apex/lwcCSVUploaderController.saveFile';
import {ShowToastEvent} from 'lightning/platformShowToastEvent';
// const columns = [
//    { label: 'Name', fieldName: 'Name' },
//    { label: 'Phone', fieldName: 'Phone', type: 'Phone' }
// ];
export default class LwcCSVUploader extends LightningElement {
   @api recordid;
//    @track columns = columns;
   @track data;
   @track fileName = '';
   @track UploadFile = 'Upload CSV File';
   @track showLoadingSpinner = false;
   @track isTrue = false;
   selectedRecords;
   filesUploaded = [];
   file;
   fileContents;
   fileReader;
   content;
   MAX_FILE_SIZE = 1500000;
   handleFilesChange(event) {
       if(event.target.files.length > 0) {
           this.filesUploaded = event.target.files;
           this.fileName = event.target.files[0].name;
       }
   }
   handleSave() {
       if(this.filesUploaded.length > 0) {
           this.uploadHelper();
       }
       else {
           this.fileName = 'Please select a CSV file to upload!!';
       }
   }
   uploadHelper() {
       this.file = this.filesUploaded[0];
      if (this.file.size > this.MAX_FILE_SIZE) {
           window.console.log('File Size is to long');
           return ;
       }
       this.showLoadingSpinner = true;
       this.fileReader= new FileReader();
       this.fileReader.onloadend = (() => {
           this.fileContents = this.fileReader.result;
           this.saveToFile();
       });
       this.fileReader.readAsText(this.file);
   }
   saveToFile() {
       saveFile({ base64Data: JSON.stringify(this.fileContents), cdbId: this.recordid})
       .then(result => {
           window.console.log('result ====> ');
           window.console.log(result);
           this.data = result;
           this.fileName = this.fileName + ' - Uploaded Successfully';
           this.isTrue = false;
           this.showLoadingSpinner = false;
           this.dispatchEvent(
               new ShowToastEvent({
                   title: 'Success!!',
                   message: this.file.name + ' - Uploaded Successfully!!!',
                   variant: 'success',
               }),
           );
       })
       .catch(error => {
           window.console.log(error);
           this.dispatchEvent(
               new ShowToastEvent({
                   title: 'Error while uploading File',
                   message: error.message,
                   variant: 'error',
               }),
           );
       });
   }
}

html:

<template>
    <template if:true={showLoadingSpinner}>
        <div style="z-index: 10000 !important;">
            <lightning-spinner alternative-text="Uploading......" size="medium" style="z-index: 10000 !important;"></lightning-spinner>
        </div>
    </template>
    <lightning-card title="Process CSV File">
        <div style="margin-left:4%; margin:0px auto; width: 300px;">
            <div>
                <lightning-input label="" name="file uploader" onchange   ={handleFilesChange} type="file" multiple></lightning-input>
            </div><br/>
            <div class="slds-text-body_small slds-text-color_error">{fileName}
            </div><br/>
            <div>
                <lightning-button class="slds-m-top--medium" label={UploadFile} onclick   ={handleSave} variant="brand" disabled={isTrue}></lightning-button>
            </div>
        </div><br/><br/>
    </lightning-card>
    
</template>

Thanks in advance.
i want to know how to deserialize json by using wrapper class to update multiple account related records like contact, opportunity, and case.

here is my wrapper class:

public with sharing class contactController {
@AuraEnabled(cacheable=true)
public static List<accWrapper> getAccountRelatedRecord(Id recordId){
List<Contact> conlist = new List<Contact>();
List<Opportunity> oppolist = new List<Opportunity>();
List<Case> clist = new List<Case>();
List<accWrapper> acclist = new List<accWrapper>();
try{
    conlist= [SELECT Id , Lastname,FirstName,Email,Phone FROM Contact WHERE AccountId =: recordId];
        oppolist = [SELECT Id, Name, CloseDate, Amount, StageName,AccountId  FROM Opportunity WHERE AccountId =:recordId ];
        clist = [SELECT Id, Status, Type, ContactId, CaseNumber FROM Case WHERE AccountId =: recordId];
        system.debug('Showlists>>>>>' + conlist);
        List<accWrapper> aclist = new List<accWrapper>();
        for (Contact cons : conlist){
            accWrapper aw = new accWrapper();
            aw.contactRecord = cons;
            aclist.add(aw);
        }
        for (Opportunity opps : oppolist){
            accWrapper aw = new accWrapper();
            aw.opportunityRecord = opps;
            aclist.add(aw);
    }
   
    for (Case cs : clist){
            accWrapper aw = new accWrapper();
            aw.caseRecord = cs;
            aclist.add(aw);
    }
    system.debug(aclist.size());
        return aclist;
}catch (Exception e){
    throw new AuraHandledException(e.getMessage());
}
}
public class accWrapper{
    @AuraEnabled
    public Contact contactRecord{get;set;}
    @AuraEnabled
    public opportunity opportunityRecord{get;set;}
    @AuraEnabled
    public case caseRecord{get;set;}
}
    }
I am facing this problem  Method does not exist or incorrect signature: void deserialize(Object) from the type System.JSON
This is my apex class:

public with sharing class contactController {
@AuraEnabled
    public static void saveContacts(List<Object> listContact)
    {
        list<contact> conlist = new list<contact>();
        //Insert listContact;
        for(Object a:listContact){
            (contact)JSON.deserialize(a);
            conlist.add((contact) JSON.deserialize(a));
           
        }
        update conlist;
    }
}

thanks in advance.
I found this error on console log.
here is my code:
public with sharing class contactController {
    @AuraEnabled(cacheable=true)
    public static List<Contact> getContacts(String accId) {
        return [
            SELECT AccountId, Id, FirstName, LastName, Title, Phone, Email
            FROM Contact
            WHERE AccountId = :accId
             
           ];
       
    }
    @AuraEnabled
    public static void saveContacts(List<Object> listContact)
    {
        list<contact> conlist = new list<contact>();
       for(Object a:listContact){
            conlist.add((contact) a);
        }
        update conlist;
    }
}


thanks in advance.
here is my code:
public with sharing class contactController {
    @AuraEnabled(cacheable=true)
    public static List<Contact> getContacts(String accId) {
        return [
            SELECT AccountId, Id, FirstName, LastName, Title, Phone, Email
            FROM Contact
            WHERE AccountId = :accId
             
           ];
       
    }
}


it will not working for updating multiple record on table.
In my code I display contact record in account record page my first name and lastname fields is read only i want to edit my phone field when click on update button phone field are updated;
here is my code:
 html:

<template>
    <lightning-card title="Update Contacts on Account Page" custom-icon="custom:icon13">
       
    <table class="slds-table slds-table_cell-buffer slds-table_bordered" border="1" cellspacing="0" cellpadding="0"  style="border-collapse:collapse;">
       
        <template if:true={record}>
        <tr>
            <td><b>FirstName</b></td>
            <td><b>LastName</b></td>
            <td><b>Phone</b></td>
        </tr>
        <template for:each={record} for:item="acc">
           
        <tr key={acc.Id}>
           
            <td><lightning-input label="First Name" value={acc.FirstName} data-field="FirstName" onchange={handleChange} class="slds-m-bottom_x-small" readonly="true"></lightning-input></td>
            <td><lightning-input label="Last Name" value={acc.LastName} data-field="LastName" onchange={handleChange} class="slds-m-bottom_x-small" readonly="true" required></lightning-input></td>
            <td><lightning-input label="Last Name" value={acc.Phone} data-field="Phone" onchange={handleChange} class="slds-m-bottom_x-small" ></lightning-input></td>
        </tr>
       
        </template>
        <lightning-button label="update"  variant="brand" onclick={handleUpdate}></lightning-button>
    </template>
    </table>
   
    </lightning-card>
</template>

js:
import { LightningElement,api,wire,track } from 'lwc';
import getContacts from '@salesforce/apex/contactController.getContacts';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { refreshApex } from '@salesforce/apex';
import { updateRecord } from 'lightning/uiRecordApi';
import ID_FIELD from '@salesforce/schema/Contact.Id';
import FIRST_NAME_FIELD from '@salesforce/schema/Contact.FirstName';
import LAST_NAME_FIELD from '@salesforce/schema/Contact.LastName';
import PHONE_FIELD from '@salesforce/schema/Contact.Phone';
export default class contactAccountInfo extends LightningElement {
  @api recordId;
  @api errorMessage;
  @track record;
  @track error;
  @track contactId;
    @track firstName;
    @track lastName;
    @track phone;
 
  fields = [LAST_NAME_FIELD,FIRST_NAME_FIELD, ID_FIELD,PHONE_FIELD];
  @wire(getContacts, { accId: '$recordId' })
  cons({error,data}){
    console.log('recordId',this.recordId);
    if (data) {
        console.log('>>>data: ' + JSON.stringify(data));
        this.record = data;
        this.error = undefined;
        console.log('recordId',this.record);
    } else if (error) {
        this.error = error;
        this.data = undefined;
    }
}
handleUpdate(event) {
    // Display field-level errors and disable button if a name field is empty.
   this.data=event.target.value;
   console.log('recordId' + data);

updateRecord({
    accId:this.data
})
.then(()=>{
    console.log('SUCCESS');
    return refreshApex(this.data);
})
.catch((error)=>{
    this.errorMessage=error;
            console.log('unable to update the record due to'+JSON.stringify(this.errorMessage));
})
}
}

help me out of this:
 
hello,
can you please me out of this 

html:
<template>
    <table class="slds-table slds-table_cell-buffer slds-table_bordered">
        <template if:true={record}>
        <tr>
            <td><b>FirstName</b></td>
            <td><b>LastName</b></td>
            <td><b>Phone</b></td>
        </tr>
        <template for:each={record} for:item="acc">
            <tr key={acc.Id}>
                <td>
                    {acc.FirstName}
                </td>
                <td>
                    {acc.LastName}
                </td>
                <td>
                    {acc.Phone}
                </td>
               
            </tr>
        </template>
        </template>
    </table>
    <lightning-button
            class="slds-m-top_small"
            variant="brand"
            type="submit"
            name="update"
            label="Update"
        >
        </lightning-button>
</template>

js:

import { LightningElement,api,wire,track } from 'lwc';
import getContacts from '@salesforce/apex/contactController.getContacts';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { refreshApex } from '@salesforce/apex';
import { updateRecord } from 'lightning/uiRecordApi';
import FIRST_NAME_FIELD from '@salesforce/schema/Contact.FirstName';
import LAST_NAME_FIELD from '@salesforce/schema/Contact.LastName';
import ID_FIELD from '@salesforce/schema/Contact.Id';
import PHONE_FIELD from '@salesforce/schema/Contact.Phone';
export default class contactAccountInfo extends LightningElement {
  @api recordId;
  @track record;
  @track error;
 
  fields = [LAST_NAME_FIELD,FIRST_NAME_FIELD, ID_FIELD,PHONE_FIELD];
  @wire(getContacts, { accId: '$recordId' })
  cons({error,data}){
    console.log('recordId',this.recordId);
    if (data) {
        console.log('>>>data: ' + JSON.stringify(data));
        this.record = data;
        this.error = undefined;
        console.log('recordId',this.record);
    } else if (error) {
        this.error = error;
        this.data = undefined;
    }
}
handleSubmit(event) {
    console.log('onsubmit event recordEditForm'+ event.detail.fields);
}
handleSuccess(event) {
    console.log('onsuccess event recordEditForm', event.detail.id);
}
updateContact(event){
    this.contactId = event.target.dataset.recordid;
     const recordInput = {
         fields: {
             [Id.fieldApiName]: this.contactId,
             [contactFirstName.fieldApiName]: this.firstName,
             [contactLastName.fieldApiName]: this.lastName,
             [contactPhone.fieldApiName]: this.phone,
         }
     };
     updateRecord(recordInput).then((resolve) => {
        this.dispatchEvent(
            new ShowToastEvent({
                title: 'Success',
                message: 'Record Updated',
                variant: 'success',
            }),
        );
        return refreshApex(this.wiredContactsResult);
    }, (reason) => {
        console.log("Reason-->",reason);
    })
    //Show error when record does not updated
    .catch(error => {
      console.log("Error:--->  ",error);
    });
  }
 
}this is the table but that is not update how to do update help me outhow i can update multiple record at a time?
This is my code its work on contact record page but not work in account record page please any one can help me.

html:
<template>
    <lightning-card title="Related Fields" custom-icon="custom:icon13">
        <template if:true={record}></template>
    <lightning-record-edit-form
   
        record-id={recordId}
        object-api-name="objectApiName"
       
        onsuccess={handleSuccess} onsubmit ={handleSubmit}>
   
        <lightning-messages> </lightning-messages>
        <lightning-output-field field-name="AccountId">
        </lightning-output-field>
        <lightning-input-field field-name="LastName"> </lightning-input-field>
        <lightning-input-field field-name="FirstName"> </lightning-input-field>
        <lightning-input-field field-name="Phone"> </lightning-input-field>
        <lightning-button
            class="slds-m-top_small"
            variant="brand"
            type="submit"
            name="update"
            label="Update"
        >
        </lightning-button>
    </lightning-record-edit-form>
  </lightning-card>
  </template>

J.S.

import { LightningElement,api,wire,track } from 'lwc';
import getContacts from '@salesforce/apex/contactController.getContacts';
import LAST_NAME_FIELD from '@salesforce/schema/Contact.LastName';
import PHONE_FIELD from '@salesforce/schema/Contact.Phone';
export default class contactAccountInfo extends LightningElement {
  @api recordId;
  @api objectApiName;
  @track contactRecord;
  fields = [LAST_NAME_FIELD, PHONE_FIELD];
  @wire(getContacts, { accId: '$recordId' })
  cons({error,data}){
    console.log('recordId',this.recordId);
    if (data) {
        console.log('>>>data: ' + JSON.stringify(data));
        this.record = data;
        this.error = undefined;
        console.log('recordId',this.record);
    } else if (error) {
        this.error = error;
        this.data = undefined;
    }
}
handleSuccess(event) {
    this.recordId = event.detail.id;
    alert('Id: '+event.detail.id);
}
  }

apex class:

public with sharing class contactController {
    @AuraEnabled(cacheable=true)
    public static List<Contact> getContacts(String accId) {
        return [
            SELECT AccountId, Id, FirstName, LastName, Title, Phone, Email
            FROM Contact
            WHERE AccountId = :accId
             
           ];
       
    }
}


Thanks in advance.
How to display opportunity associated all products in trigger.
Here is my code:
trigger opportunityProductCount on Product2 (after insert, after update, after delete, after undelete) {
    set<Id> setIds = new set<Id>();
    list<Opportunity> opplist= new list<Opportunity>();
    if(trigger.isafter){
        if(trigger.isinsert|| trigger.isUpdate|| trigger.isUndelete){
            for(Product2 p: trigger.new){
                setIds.add(p.OpportunityId);
            }
        }
        if(trigger.isupdate|| trigger.isdelete){
            for(Product2 po:trigger.old){
                setIds.add(po.OpportunityId);
            }
        }
    }
    List<Opportunity> oplist = [Select Id,Name,Number_of_Product__c,(select id,name from Products2)from Opportunity where Id in:setIds];
    system.debug('show products'+ oplist);
    for (Opportunity opp: oplist){
        Integer count = opp.Products2.size();
        opp.Number_of_Product__c = count;
        opplist.add(opp);
        
    }
    update opplist;

}
Can anybody help to out of this que how to associated record and count display in oppoprtunity in trigger.I just started to learn development.
here is my code:

for(case c : lstCase){
            if(c.Latest_Comment__c==Null||c.Latest_Comment__c!=Null){
                c.Latest_Comment__c=c.Comments;
                
            }
        }


But this will work only when create a new case when update comment in that case it will not getting output.
If anybody know then please help me out of this problem
Thanks in Advance.
The requirement is show the excell file in object-account in lwc.
I am facing this problem  Method does not exist or incorrect signature: void deserialize(Object) from the type System.JSON
This is my apex class:

public with sharing class contactController {
@AuraEnabled
    public static void saveContacts(List<Object> listContact)
    {
        list<contact> conlist = new list<contact>();
        //Insert listContact;
        for(Object a:listContact){
            (contact)JSON.deserialize(a);
            conlist.add((contact) JSON.deserialize(a));
           
        }
        update conlist;
    }
}

thanks in advance.
I found this error on console log.
here is my code:
public with sharing class contactController {
    @AuraEnabled(cacheable=true)
    public static List<Contact> getContacts(String accId) {
        return [
            SELECT AccountId, Id, FirstName, LastName, Title, Phone, Email
            FROM Contact
            WHERE AccountId = :accId
             
           ];
       
    }
    @AuraEnabled
    public static void saveContacts(List<Object> listContact)
    {
        list<contact> conlist = new list<contact>();
       for(Object a:listContact){
            conlist.add((contact) a);
        }
        update conlist;
    }
}


thanks in advance.
In my code I display contact record in account record page my first name and lastname fields is read only i want to edit my phone field when click on update button phone field are updated;
here is my code:
 html:

<template>
    <lightning-card title="Update Contacts on Account Page" custom-icon="custom:icon13">
       
    <table class="slds-table slds-table_cell-buffer slds-table_bordered" border="1" cellspacing="0" cellpadding="0"  style="border-collapse:collapse;">
       
        <template if:true={record}>
        <tr>
            <td><b>FirstName</b></td>
            <td><b>LastName</b></td>
            <td><b>Phone</b></td>
        </tr>
        <template for:each={record} for:item="acc">
           
        <tr key={acc.Id}>
           
            <td><lightning-input label="First Name" value={acc.FirstName} data-field="FirstName" onchange={handleChange} class="slds-m-bottom_x-small" readonly="true"></lightning-input></td>
            <td><lightning-input label="Last Name" value={acc.LastName} data-field="LastName" onchange={handleChange} class="slds-m-bottom_x-small" readonly="true" required></lightning-input></td>
            <td><lightning-input label="Last Name" value={acc.Phone} data-field="Phone" onchange={handleChange} class="slds-m-bottom_x-small" ></lightning-input></td>
        </tr>
       
        </template>
        <lightning-button label="update"  variant="brand" onclick={handleUpdate}></lightning-button>
    </template>
    </table>
   
    </lightning-card>
</template>

js:
import { LightningElement,api,wire,track } from 'lwc';
import getContacts from '@salesforce/apex/contactController.getContacts';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { refreshApex } from '@salesforce/apex';
import { updateRecord } from 'lightning/uiRecordApi';
import ID_FIELD from '@salesforce/schema/Contact.Id';
import FIRST_NAME_FIELD from '@salesforce/schema/Contact.FirstName';
import LAST_NAME_FIELD from '@salesforce/schema/Contact.LastName';
import PHONE_FIELD from '@salesforce/schema/Contact.Phone';
export default class contactAccountInfo extends LightningElement {
  @api recordId;
  @api errorMessage;
  @track record;
  @track error;
  @track contactId;
    @track firstName;
    @track lastName;
    @track phone;
 
  fields = [LAST_NAME_FIELD,FIRST_NAME_FIELD, ID_FIELD,PHONE_FIELD];
  @wire(getContacts, { accId: '$recordId' })
  cons({error,data}){
    console.log('recordId',this.recordId);
    if (data) {
        console.log('>>>data: ' + JSON.stringify(data));
        this.record = data;
        this.error = undefined;
        console.log('recordId',this.record);
    } else if (error) {
        this.error = error;
        this.data = undefined;
    }
}
handleUpdate(event) {
    // Display field-level errors and disable button if a name field is empty.
   this.data=event.target.value;
   console.log('recordId' + data);

updateRecord({
    accId:this.data
})
.then(()=>{
    console.log('SUCCESS');
    return refreshApex(this.data);
})
.catch((error)=>{
    this.errorMessage=error;
            console.log('unable to update the record due to'+JSON.stringify(this.errorMessage));
})
}
}

help me out of this:
 
hello,
can you please me out of this 

html:
<template>
    <table class="slds-table slds-table_cell-buffer slds-table_bordered">
        <template if:true={record}>
        <tr>
            <td><b>FirstName</b></td>
            <td><b>LastName</b></td>
            <td><b>Phone</b></td>
        </tr>
        <template for:each={record} for:item="acc">
            <tr key={acc.Id}>
                <td>
                    {acc.FirstName}
                </td>
                <td>
                    {acc.LastName}
                </td>
                <td>
                    {acc.Phone}
                </td>
               
            </tr>
        </template>
        </template>
    </table>
    <lightning-button
            class="slds-m-top_small"
            variant="brand"
            type="submit"
            name="update"
            label="Update"
        >
        </lightning-button>
</template>

js:

import { LightningElement,api,wire,track } from 'lwc';
import getContacts from '@salesforce/apex/contactController.getContacts';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { refreshApex } from '@salesforce/apex';
import { updateRecord } from 'lightning/uiRecordApi';
import FIRST_NAME_FIELD from '@salesforce/schema/Contact.FirstName';
import LAST_NAME_FIELD from '@salesforce/schema/Contact.LastName';
import ID_FIELD from '@salesforce/schema/Contact.Id';
import PHONE_FIELD from '@salesforce/schema/Contact.Phone';
export default class contactAccountInfo extends LightningElement {
  @api recordId;
  @track record;
  @track error;
 
  fields = [LAST_NAME_FIELD,FIRST_NAME_FIELD, ID_FIELD,PHONE_FIELD];
  @wire(getContacts, { accId: '$recordId' })
  cons({error,data}){
    console.log('recordId',this.recordId);
    if (data) {
        console.log('>>>data: ' + JSON.stringify(data));
        this.record = data;
        this.error = undefined;
        console.log('recordId',this.record);
    } else if (error) {
        this.error = error;
        this.data = undefined;
    }
}
handleSubmit(event) {
    console.log('onsubmit event recordEditForm'+ event.detail.fields);
}
handleSuccess(event) {
    console.log('onsuccess event recordEditForm', event.detail.id);
}
updateContact(event){
    this.contactId = event.target.dataset.recordid;
     const recordInput = {
         fields: {
             [Id.fieldApiName]: this.contactId,
             [contactFirstName.fieldApiName]: this.firstName,
             [contactLastName.fieldApiName]: this.lastName,
             [contactPhone.fieldApiName]: this.phone,
         }
     };
     updateRecord(recordInput).then((resolve) => {
        this.dispatchEvent(
            new ShowToastEvent({
                title: 'Success',
                message: 'Record Updated',
                variant: 'success',
            }),
        );
        return refreshApex(this.wiredContactsResult);
    }, (reason) => {
        console.log("Reason-->",reason);
    })
    //Show error when record does not updated
    .catch(error => {
      console.log("Error:--->  ",error);
    });
  }
 
}this is the table but that is not update how to do update help me outhow i can update multiple record at a time?
please anybody help me out of this i am a fersher on lwc.

thanks in advance.
HTML:
<template>
    <lightning-card title="LWC Related fields">
        <template if:true={contactRecord}>
        <lightning-datatable record-id={recordId}
         data={contactRecord} columns={columns} key-field="Id">
        </lightning-datatable>
    </template>
    </lightning-card>
</template>
/////////////////////////////////////////////////////////////////////////
J.S
import { LightningElement,wire,track,api } from 'lwc';
import getAccountRelatedRecord from '@salesforce/apex/accountController.getAccountRelatedRecord';
export default class DisplayRelatedFieldsOnAccount extends LightningElement {
@api recordId;
@track contactRecord;

@track columns = [
    { label: 'FirstName', fieldName: 'FirstName', type: 'text' },
    { label: 'LastName', fieldName: 'LastName', type: 'text' },
    { label: 'Email', fieldName: 'Email'},
    { label: 'Phone', fieldName: 'Phone', type: 'Phone' }
];
@wire(getAccountRelatedRecord, { recordId: '$recordId'})
wireConRecord({error, data}){
    console.log('recordId',this.recordId);
    if(data){
        this.contactRecord = data;
        this.error = undefined;
        console.log('recordId',this.contactRecord);
    }
    else {
        this.error = error;
        this.contactRecord = undefined;
        console.log(error);
    }
}

}
////////////////////////////////////////////////////////////////////////////////
WRAPPER CLASS:

public class accountController{
@AuraEnabled(cacheable = true)
public static List<accWrapper> getAccountRelatedRecord(Id recordId){
 List<Contact> conlist = new List<Contact>();
List<accWrapper> acclist = new List<accWrapper>();
    try{
            conlist= [SELECT Id , Lastname,FirstName,Email,Phone FROM Contact WHERE AccountId =: recordId];
system.debug('Showlists>>>>>' + conlist);
            List<accWrapper> aclist = new List<accWrapper>();
            for (Contact cons : conlist){
                accWrapper aw = new accWrapper();
                aw.contactRecord = cons;
                aclist.add(aw);
            }
 return aclist;
} catch (Exception e){
        throw new AuraHandledException(e.getMessage());
    }
}
public class accWrapper{
    @AuraEnabled
    public Contact contactRecord{get;set;}
}
////////////////////////////////////////////////////////////////////////////////////////////User-added imagethis is my table please help me out of this.
Hi folks.
I did the INLINE EDITING in SLDS table LWC. When user updated the record with INLINE EDITING and clicks on SAVE the record not updating. Record updates only when we RELOAD THE PAGE. Record should update as soon as user click on save. Please help me regarding this. Refer below HTML and JS code. Let me know any change in refreshApex()..
-------------------HTML-------------------
<template>
    <div class="slds-m-bottom_large">
        <div class="slds-grid slds-gutters">
            <div class="slds-col slds-size_4-of-5" style='font-weight: 500;font-size: 18px'>
                <span>RMA Case Line Item History</span>
            </div>
        </div>
    </div>
    <div class="landingpagebody">      
        <lightning-card title="">          
        <div class="slds-m-top_large">                  
            <lightning-datatable draft-values={draftValues}  
                                show-row-number-column 
                                onsave={handleSave} 
                                key-field="Id" 
                                data={rmarecord} 
                                columns={columns}
                                onrowselection={updateSelected}
                                oncellchange={cellChange}  
                                onclick={navRecordpage}></lightning-datatable>                             
        </div>
    </lightning-card>
    </div>
</template>
------------------------JS----------------------------
import { LightningElement, wire, track, api} from 'lwc';
import { getRecord, getFieldValue } from "lightning/uiRecordApi";
//import CONTACT_ID from "@salesforce/schema/User.ContactId";
import USER_ID from "@salesforce/user/Id";
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import getSelectedCaseLineItems from '@salesforce/apex/rmaCaseLineItemController.getSelectedCaseLineItems';
import updateCases from '@salesforce/apex/rmaCaseLineItemController.updateCases';
import { refreshApex } from '@salesforce/apex';
import { updateRecord } from 'lightning/uiRecordApi';

 // import { recordId } from 'lightning/uiRecordApi';

export default class RmaCaseLineItem extends LightningElement {
    
    @api recordId;
    objectApiName = 'R4C_Case_Line_Item__c'; 
    @track rmarecord;
    @track conid;
    @track error;
    @track draftValues = [];
    wiredRecords;

    @track columns = [ 
       
        {label:'Approval status', fieldName:'Approval_status__c', type: 'boolean',editable: true},
        {label:'PO#', fieldName:'Name', type:'url', 
        typeAttributes: {
            label: { 
                fieldName: 'Name' 
            },
            target : '_blank'
        }
        },        
        {label:'SO#', fieldName:'SO__c', type:'text'},
        {label:'PO Date', fieldName:'PO_Date__c',type:'text'},
        {label:'Sold To', fieldName:'Sold_To__c', type:'text'},
        {label:'Ship To', fieldName:'Ship_To__c', type:'text'},
        {label:'Line Item', fieldName:'Line_Item__c', type:'text'},
        {label:'Intel Product Number', fieldName:'MMID__c',type:'text'},
        {label:'Intel Product Name', fieldName:'EPM_Name__c', type:'text'},
        {label:'Customer Part Number', fieldName:'Stocking_ID__c', type:'text'},
        {label:'Quantity', fieldName:'Quantity__c', type:'text'},
        {label:'Return Quantity',fieldName:'Return_Quantity__c', type:'number'},
        {label:'Billed Quantity', fieldName:'Billed_Quantity__c',type:'text'},
        {label:'Net value', fieldName:'Net_Value__c', type:'currency'},
        
    ]
    @wire(getSelectedCaseLineItems, {caseid: '$recordId'}) caseLineItems({data, error}){
        
        if(data){
            this.rmarecord = data;
            console.log(data);
          //  console.log(recordId);
        }
        if(error){
            console.log(error);
        }
    }
    
    handleSave(event){
      //  this.draftValues = event.detail.draftValues;
        const recordInputs = event.detail.draftValues.slice().map(draft => {
            const fields = Object.assign({}, draft);
            return { fields };
        });
         console.log('RECORDINPUTS', JSON.stringify(recordInputs));
        // Updating the records using the UiRecordAPi
        const promises = recordInputs.map(recordInput => updateRecord(recordInput));
        Promise.all(promises).then(rmarecord => {
            this.dispatchEvent(
                new ShowToastEvent({
                    title: 'Success',
                    message: 'Records Updated Successfully!!',
                    variant: 'success'
                })
            );
            this.draftValues = [];
            // Display fresh data in the datatable
             return this.refresh;
        }).catch(error => {
            this.dispatchEvent(
                new ShowToastEvent({
                    title: 'Error',
                    message: 'An Error Occured!!',
                    variant: 'error'
                })
            );
        })  .finally(() => {
            this.draftValues = [];
        }); 
    
    }
    
    
    
    
    // This function is used to refresh the table once data updated
    async refresh() {
        await refreshApex(this.rmarecord);
    } 
  
}
-----------------------------------------------------------------------------
Can anyone help me out inwriting wrapper class to fetch fields from different objects to show it on Lighning web component.

For an account I want to fetch fields from Contact, Case,Opportunity objects so that thosevales will be shown on LWC.

Can anyone help me out in this.