• RK Bheemreddy
  • NEWBIE
  • 0 Points
  • Member since 2017

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

I am new to lwc and java script and I am currently working on a feature to display a list of records with inline edit from an object in a lightning page.
The list of records need to be displayed in different sections based on a picklist field on the same object and when a user updates the picklist field value on any of the records, the table must be refreshed based on the picklist values.

I tried doing this with two different datatables and I am unable to refresh all the tables when a user makes an update. Below is my code.

Any help is greatly appreciated.

Apex Class:

public with sharing class ContactController {
    @AuraEnabled(cacheable = true)
    public static List<Contact> getWebContactList(){
        return [SELECT Id, FirstName, LastName, Title, Phone, Email, LeadSource FROM Contact where LeadSource =: 'Web' LIMIT 10];
    }
    @AuraEnabled(cacheable = true)
    public static List<Contact> getPhoneContactList(){
        return [SELECT Id, FirstName, LastName, Title, Phone, Email, LeadSource FROM Contact where LeadSource =: 'Phone Inquiry' LIMIT 10];
    }
    @AuraEnabled(cacheable=true)
    public static List<Contact> getContactList() {
        return [SELECT Id, FirstName, LastName, Title, Phone, Email, LeadSource FROM Contact where (LeadSource =: 'Phone Inquiry' OR LeadSource =: 'Web') LIMIT 10];
    }
}

JS Controller:

import { LightningElement, wire, track } from 'lwc';
import getContactList from '@salesforce/apex/ContactController.getContactList';
import getWebContactList from '@salesforce/apex/ContactController.getWebContactList';
import getPhoneContactList from '@salesforce/apex/ContactController.getPhoneContactList';
import { updateRecord } from 'lightning/uiRecordApi';
import { refreshApex } from '@salesforce/apex';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import FIRSTNAME_FIELD from '@salesforce/schema/Contact.FirstName';
import LASTNAME_FIELD from '@salesforce/schema/Contact.LastName';
import ID_FIELD from '@salesforce/schema/Contact.Id';
import LEADSOURCE_FIELD from '@salesforce/schema/Contact.LeadSource';

const COLS = [
    { label: 'First Name', fieldName: 'FirstName', editable: true },
    { label: 'Last Name', fieldName: 'LastName', editable: true },
    { label: 'Lead Source', fieldName: 'LeadSource', editable: true },
    { label: 'Title', fieldName: 'Title' },
    { label: 'Phone', fieldName: 'Phone', type: 'phone' },
    { label: 'Email', fieldName: 'Email', type: 'email' }
];
export default class DatatableUpdateExample extends LightningElement {
    @track contacts;
    @track error;
    @track columns = COLS;
    @track draftValues = [];
    wiredContactResult;
    @wire(getContactList)
    wiredContacts(result) {
        this.wiredContactResult = result;
        if(result.data) {
            this.contacts = result.data;
            this.error = undefined;
        } else if (result.error) {
            this.error = result.error;
            this.contacts = undefined;
        }
    }
    
    @wire(getWebContactList)
    webContact;
    @wire(getPhoneContactList)
    phoneContact;
    handleSave(event) {
        const recordInputs =  event.detail.draftValues.slice().map(draft => {
            const fields = Object.assign({}, draft);
            return { fields };
        });
    
        const promises = recordInputs.map(recordInput => updateRecord(recordInput));
        
        Promise.all(promises).then(contacts => {
            this.dispatchEvent(
                new ShowToastEvent({
                    title: 'Success',
                    message: 'Contacts updated',
                    variant: 'success'
                })
            );
             // Clear all draft values
             this.draftValues = [];
    
             // Display fresh data in the datatable
             return refreshApex(this.phoneContact);
        }).catch(error => {
            // Handle error
        });
    }   
    handleWebSave(event) {
        const recordInputs =  event.detail.draftValues.slice().map(draft => {
            const fields = Object.assign({}, draft);
            return { fields };
        });
    
        const promises = recordInputs.map(recordInput => updateRecord(recordInput));
        
        Promise.all(promises).then(contacts => {
            this.dispatchEvent(
                new ShowToastEvent({
                    title: 'Success',
                    message: 'Contacts updated',
                    variant: 'success'
                })
                
            );
            
             // Clear all draft values
             this.draftValues = [];
            
             // Display fresh data in the datatable
             return refreshApex(this.webContact);
             
        }).catch(error => {
            // Handle error
        });
    }
}

HTML:

<template>
    <lightning-card title="Datatable Example" icon-name="custom:custom63">
        <div class="slds-m-around_medium">
            <template if:true={webContact.data} >
                <lightning-datatable
                    key-field="Id"
                    data={webContact.data}
                    columns={columns}
                    onsave={handleWebSave}
                    draft-values={draftValues}>
                </lightning-datatable>
            </template>
            <template if:true={webContact.error}>
                <!-- handle Apex error -->
            </template>
        </div>
        <div class="slds-m-around_medium">
            <template if:true={phoneContact.data}>
                <lightning-datatable
                    suppressbottombar = "false"
                    key-field="Id"
                    data={phoneContact.data}
                    columns={columns}
                    onsave={handleSave}
                    draft-values={draftValues}>
                </lightning-datatable>
            </template>
            <template if:true={phoneContact.error}>
                <!-- handle Apex error -->
            </template>
        </div>
    </lightning-card>
</template>
I wanted to check if this is a known issue. On saturday our instance was upgraded to Summer 19, and on monday we started seeing Apex CPU time Limit Exceeded error on one of our objects.

Could someone let me know if they are aware of the issue.

Thanks
Ravi
Hi, 

I am struggling to find out what the issue could be. I had created a visualforce page for salesforce sites. For some reason, the page doesn't load for the guest user. I tried to preview as an admin and found the below error. 

inputField> value binding '{!reference[field.Name]}' in page referencesubmissionformcustom

The same code and the setup is working fine in sandbox and I have verified every single permission on the guest user profile.

Any help is greatly appreciated.

Thanks
Ravi
Hi,

My requirement is to attach a Case to a Contact only when the Supplied email matches the Primary Email of a Contact in the system. Currently, Salesforce OOTB feature links a Case to a Contact if the Supplied Email matches any custom or standard Email on the Contact. I wrote a trigger to match a  User in the system to a custom lookup field. I have no idea how to achieve the Contact thing from here.

Any help is greatly appreciated.

Thanks,
RK

trigger EmailtoCaseTrigger on Case (before insert) {
    
    
    set<String> casebyEmail = new set<String>();
    map<string,string> userEmailIdMap = new map<string, string>();
    
    for(Case c: trigger.new){
        casebyEmail.add(c.SuppliedEmail);
    }
    
    List<User> matchingUsers = [Select Id, Name, Email from User where Email IN: casebyEmail limit 1000];
    
    for(User u: matchingUsers){
        userEmailIdMap.put(u.Email,u.Id);
    }
    
    for(Case c: Trigger.new){
        c.Requestor__c = userEmailIdMap.get(c.SuppliedEmail);
    }    
    }
Hi,

We are using Drawloop to generate contracts and Docusign to send the contract for esignature. The custom java script button that is created doesn't work as expected when we try to pass the Contact name as a Signer when there is a special character in the Contact Name. I was able to escape single quote using JSENCODE function but when there is a comma in the name, it still doesn't work. Any help is greatly appreciated.

Thanks,
-Ravi
Hi All,

We are planning to implement a process for handling change requests and enhancements. Currently users create a Case within salesforce and let us know if they need a change or they have an issue. Ideally we would like to group similar enhancement requests into one and have a process in place where it goes through requirements Gathering, Design, Dev, QA Testing, UAT and Release.

Can someone guide me through what an ideal approach would be to achieve this?

Thanks,
-RK

 
I wanted to check if this is a known issue. On saturday our instance was upgraded to Summer 19, and on monday we started seeing Apex CPU time Limit Exceeded error on one of our objects.

Could someone let me know if they are aware of the issue.

Thanks
Ravi
Hi,

We are using Drawloop to generate contracts and Docusign to send the contract for esignature. The custom java script button that is created doesn't work as expected when we try to pass the Contact name as a Signer when there is a special character in the Contact Name. I was able to escape single quote using JSENCODE function but when there is a comma in the name, it still doesn't work. Any help is greatly appreciated.

Thanks,
-Ravi