• ravi soni
  • PRO
  • 3026 Points
  • Member since 2020
  • Developer
  • ACS


  • Chatter
    Feed
  • 98
    Best Answers
  • 0
    Likes Received
  • 4
    Likes Given
  • 0
    Questions
  • 455
    Replies
Hi!
I have leadtable as in the image.

User-added image

I need get leads in input fields to save them automatically, not in columns. Please tell me how can I do that.

My code:
Html

<template>
    <lightning-card title="Leads">
        <lightning-layout multiple-rows="true" vertical-align="end">
           
            <lightning-layout-item size="12" padding="around-small">
                <lightning-datatable key-field="id" data={leads} columns={columns}>
                   
                </lightning-datatable>
                <lightning-input class="slds-p-around_medium" label="Name" name="leadName"
                    onchange={nameChangedHandler}></lightning-input>
                    <lightning-input class="slds-p-around_medium" label="Title" name="leadTitle"
                    onchange={titleChangedHandler}></lightning-input>
                <lightning-input class="slds-p-around_medium" label="Phone" type="phone" name="leadPhone"
                    onchange={phoneChangedHandler}></lightning-input>
                <br/>
            </lightning-layout-item>
           
        </lightning-layout>
    </lightning-card>
</template>

Js
import { LightningElement, wire } from 'lwc';
import getLeads from '@salesforce/apex/ProjectThree.getLeads';
import LEAD_OBJECT from '@salesforce/schema/Lead';
import NAME_FIELD from '@salesforce/schema/Lead.Title';
import TITLE_FIELD from '@salesforce/schema/Lead.Title';
import PHONE_FIELD from '@salesforce/schema/Lead.Phone';
const columns = [
    { label: 'Name', fieldName: 'recordLink', type: 'url',
        typeAttributes: {label: {fieldName: "LeadName"}, tooltip: "Name", linkify: true} },
    { label: 'Title', fieldName: 'Title', type: 'text', editable: true },
    { label: 'Phone', fieldName: 'Phone', type: 'text', editable: true }    
];
export default class LdsCreateRecord extends LightningElement {
    columns = columns;
    leads;
    lead = LEAD_OBJECT;
    myFields = [NAME_FIELD, TITLE_FIELD, PHONE_FIELD];
    strName;
    strTitle;
    strPhone;
    // Change Handlers.
    nameChangedHandler(event){
        this.strName = event.target.value;
    }
    titleChangedHandler(event){
        this.strAccountNumber = event.target.value;
    }
    phoneChangedHandler(event){
        this.strPhone = event.target.value;
    }
 
    @wire(getLeads)
    wiredLeads(value) {
        const {error, data} = value;
        if (data) {
            let leadData = JSON.parse(JSON.stringify(data));  
            leadData.forEach(record => {
                record.recordLink = "/" + record.Id;  
                record.LeadName = record.Name;
            });  
            this.leads = leadData;
        } else if (error) {
            this.error = error;
        }
    }
}

public with sharing class ProjectThree {
    @AuraEnabled(cacheable=true)
    public static List<Lead> getLeads() {
        List<Lead> leads = [
            SELECT Id, Name, Title, Phone
            FROM Lead         
            //WHERE Name Like 'Lisa%'
            Limit 3
        ];
        System.debug('leads = ' + leads);
        return leads;                
    }  
}   
Hi everyone!
I have contact table and need to get Id + Name as concatenation of Id '0032v000034aSJyAAM' and string 'Name' like on the image.

User-added image

Please tell me how can I do that.

Here is code:

Html:
<template>
    <lightning-card title="Contacts">
        <lightning-layout multiple-rows="true" vertical-align="end">
           
            <lightning-layout-item size="12" padding="around-small">
                <lightning-datatable key-field="id" data={contacts} columns={columns}></lightning-datatable>
            </lightning-layout-item>
           
        </lightning-layout>
    </lightning-card>
</template>

Js:
import { LightningElement , wire} from 'lwc';
import getContacts from '@salesforce/apex/Qqq.getContacts';
let N = 'Name';
const columns = [    
    { label: 'idName', fieldName: 'Id' + N, type: 'text' },
    { label: 'Name', fieldName: 'recordLink', type: 'url',
    typeAttributes: {label: {fieldName: "ContactName"}, tooltip: "Name", linkify: true} }  
];
export default class ContactTable extends LightningElement {
    columns = columns;
    contacts;
   
    @wire(getContacts)
    wiredContacts(value) {
        const {error, data} = value;
        if (data) {
            let contactData = JSON.parse(JSON.stringify(data));  
            contactData.forEach(record => {
                                record.recordLink = "/" + record.Id;  
                                record.ContactName = record.Name;
                        });  
            this.contacts = contactData;
        } else if (error) {
            this.error = error;
        }
    }
}

Apex:
public with sharing class Qqq {
    @AuraEnabled(cacheable=true)
    public static List<Lead> getLeads() {
        List<Lead> leads = [
            SELECT Id, Name, Title, Phone
            FROM Lead         
            WHERE Name Like 'Lisa%'
            Limit 3
        ];
        System.debug('leads = ' + leads);
        return leads;                
    }   
    
    @AuraEnabled(cacheable=true)
    public static List<Contact> getContacts() {
        List<Contact> contacts = [
            SELECT Id, Name
            FROM Contact     
            //WHERE LastName Like 'Apex%'
            Limit 3            
        ];        
        System.debug('contacts = ' + contacts);
        return contacts;    
    }   
}

 
Hi!
I have lead table.
User-added image

I need that when I click on the name of the lead, it opens the detail page current Lead.
The link seems to work, but the detail page current Lead does not open. Please tell me how to fix it.

My code:
Html:
<template>
    <lightning-card title="Leads">
        <lightning-layout multiple-rows="true" vertical-align="end">
           
            <lightning-layout-item size="12" padding="around-small">
                <lightning-datatable key-field="id" data={leads} columns={columns}></lightning-datatable>
            </lightning-layout-item>
           
        </lightning-layout>
    </lightning-card>
</template>

Js:
import { LightningElement , wire} from 'lwc';
import getLeads from '@salesforce/apex/Qqq.getLeads';
const columns = [
    { label: 'Name', fieldName: 'Name', type: 'url',
    typeAttributes: {label: {fieldName: "Name"}, tooltip: "Name", linkify: true} },
    { label: 'Title', fieldName: 'Title', type: 'text' },
    { label: 'Phone', fieldName: 'Phone', type: 'text' }    
];
export default class LightningDatatableLWCExample extends LightningElement {
    columns = columns;
    leads;
   
    @wire(getLeads)
    wiredLeads(value) {
        const {error, data} = value;
        if (data) {
            let leadData = JSON.parse(JSON.stringify(data));  
            leadData.forEach(record => {
                            if (record.LeadId) {
                                record.recordLink = "/" + record.LeadId;  
                                record.LeadName = record.Lead.Name;
                            }
                        });  
            this.leads = leadData;
        } else if (error) {
            this.error = error;
        }
    }
}
 
Hi everyone.
I created a contact using lightning-input.
But I need to create a contact (and lookup search Account) using lightning-input-field. I сan't link html with js and Apex. Please tell me how can I do that. (I must use Apex).


My code with lightning-input that works:

Html:
<template>
    <lightning-card if:true={showModal}>
       <section role="dialog" tabindex="-1" aria-labelledby="modal-heading-01" aria-modal="true" class="slds-modal slds-fade-in-open">
            <div class="slds-modal__container">
                <lightning-button-icon class="slds-modal__close" title="Close" icon-name="utility:close" icon-class="slds-button_icon-inverse" onclick={handleDialogClose}></lightning-button-icon>
                <div class="slds-modal__header">
                    <h1 id="modal-heading-01" class="slds-modal__title slds-hyphenate">Create contact with custom lookup</h1>
                </div>
                <div class="slds-modal__content slds-p-around_medium" id="modal-content-id-1">                   
                    
                    
                    
                    <lightning-card title="New contact" icon-name="standard:contact">
                        <div class="slds-p-around_x-small">
                           
                            <lightning-input  type="text" label="Last name" value={rec.LNAME} onchange={handlelnameChange}></lightning-input>
                           
                            
                            <br/>
                            <lightning-button label="Save" onclick={handleClick}></lightning-button>
                        </div>
                    </lightning-card>


                </div>    
            </div>
        </section>
        <div class="slds-backdrop slds-backdrop_open" role="presentation"></div>
    </lightning-card>
</template>

Js:
import { LightningElement, api, wire, track } from 'lwc';
import LNAME_FIELD from '@salesforce/schema/Contact.LastName';
import insertContact from '@salesforce/apex/ContactTableProjectSecond.addContact';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import getContacts from '@salesforce/apex/ContactTableProjectSecond.getContacts';
import {refreshApex} from "@salesforce/apex";

export default class LwcNewContactUsingApexImperativecalling extends LightningElement {

    showModal = false;
    
    @track lname =LNAME_FIELD;
      
     rec={       
         LNAME:this.lname,        
      }

    @wire(getContacts)
    wiredCallback(result) {
        this._wiredResult = result;
    }

    handlelnameChange(event) {
        this.rec.LNAME = event.target.value;
        window.console.log("LNAME", this.rec.LNAME);
    }

    handleClick() {
        const contact = {
         
            LastName: this.rec.LNAME,
       
        }
        insertContact ({ con : contact })
            .then(() => {
                // this.rec={}; // Don't. You aren't clearing the value of rec properties, you're removing them. So everywhere you're using them you'll get an error because they will be now undefined properties.
            
                this.rec.LNAME = null;
               
                this.dispatchEvent(
                    new ShowToastEvent({
                        title: 'Success',
                        message: 'Contact created',
                        variant: 'success',
                    }),
                );
            })
            .catch((error) => {
                this.dispatchEvent(
                    new ShowToastEvent({
                        title: 'Error creating record',
                        message: error.body.message,
                        variant: 'error',
                    }),
                );
                console.log('error', JSON.stringify(error));
            });
    }

    @api show() {
        this.showModal = true;
    }

    handleDialogClose() {
        this.showModal = false;
    }   

    // @track selectedAccountId;
    // handleSelected(event){
    //     console.log(event.detail);
    //     this.selectedAccountId = event.detail;
    // }
}

Apex:
public with sharing class ContactTableProjectSecond {
    @AuraEnabled(cacheable=true)
    public static List<Contact> getContacts() {
        return [
            SELECT Id, FirstName, LastName, Phone, Email, Account.Name, AccountId, CreatedDate
            FROM Contact
        ];
    }
    
    @AuraEnabled(cacheable=true)
    public static List<Contact> searchContacts(String searchKey) {
        String searchKeyword = '%' + searchKey + '%';
        List<Contact> contacts = [
            SELECT Id, FirstName, LastName, Phone, Email, Account.Name, AccountId, CreatedDate
            FROM Contact
            WHERE Name LIKE :searchKeyword
        ];
        return contacts;        
    }

    @AuraEnabled
    public static void deleteContact(Id recordId) {   
        List<Contact> contact = [SELECT Id FROM Contact WHERE Id = :recordId];
        delete contact;   
   }
    
    @AuraEnabled
    public static Contact addContact(Contact con) {
        //Contact contact = new Contact(); 
        system.debug('con'+con);
    insert con;
        return con;
    } 
    
    @AuraEnabled(cacheable=true)
    public static List<account> getCustomLookupAccount(String actName) {
        List<account> accountLookupList =  new List<account>();
        System.debug('accountLookupList' + accountLookupList);
            if (actName != '') {
            String accountName = '%' + actName + '%';
            accountLookupList = [SELECT Id, Name FROM Account WHERE Name like:accountName];
            return accountLookupList;
            }
        return accountLookupList;
        }  
}

My code with lightning-input-field that doesn’t work:

Html:
<template>
    <lightning-card if:true={showModal} title={cardTitle}>
       <section role="dialog" tabindex="-1" aria-labelledby="modal-heading-01" aria-modal="true" class="slds-modal slds-fade-in-open">
            <div class="slds-modal__container">
                <lightning-button-icon class="slds-modal__close" title="Close" icon-name="utility:close" icon-class="slds-button_icon-inverse" onclick={handleDialogClose}></lightning-button-icon>
                <div class="slds-modal__header">
                    <h1 id="modal-heading-01" class="slds-modal__title slds-hyphenate">Create contact with custom lookup</h1>
                </div>
                <div class="slds-modal__content slds-p-around_medium" id="modal-content-id-1">                   
                    
                    
                    <lightning-card title={cardTitle}>                    
                    <div class="slds-m-around_medium">
                        <lightning-record-edit-form object-api-name="Contact">
                        
                            <lightning-input-field field-name="LastName">
                            </lightning-input-field> 
                            <lightning-input-field field-name="AccountId" value={recordId}>
                            </lightning-input-field>
                                <lightning-button
                                label="Save" onclick={handleClick}>
                                </lightning-button>
                        </lightning-record-edit-form>
                    </div>
                </lightning-card>


                </div>    
            </div>
        </section>
        <div class="slds-backdrop slds-backdrop_open" role="presentation"></div>
    </lightning-card>
</template>

Js:
import { LightningElement, api, wire, track } from 'lwc';
import LNAME_FIELD from '@salesforce/schema/Contact.Name';
//import LNAME_FIELD from '@salesforce/schema/Contact.LastName';
import insertContact from '@salesforce/apex/ContactTableProjectSecond.addContact';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import getContacts from '@salesforce/apex/ContactTableProjectSecond.getContacts';
import {refreshApex} from "@salesforce/apex";

export default class LwcNewContactUsingApexImperativecalling extends LightningElement {

    showModal = false;
 
    LastName = LNAME_FIELD;

    field={       
        LNAME:this.LastName,       
     }

    @api recordId;
  
    @wire(getContacts)
    wiredCallback(result) {
        this._wiredResult = result;
    }

    handlelnameChange(event) {
        this.field.LNAME = event.target.value;
        window.console.log("LNAME", this.field.LNAME);
    }

    handleClick(event) {
        console.log("handleClick", event);
        const contact = {
         
            LastName: this.field.LNAME,
       
        }
        insertContact ({ con : contact })
            .then(() => {
                // this.rec={}; // Don't. You aren't clearing the value of rec properties, you're removing them. So everywhere you're using them you'll get an error because they will be now undefined properties.
            
                this.field.LNAME = null;
               
                this.dispatchEvent(
                    new ShowToastEvent({
                        title: 'Success',
                        message: 'Contact created',
                        variant: 'success',
                    }),
                );
            })
            .catch((error) => {
                this.dispatchEvent(
                    new ShowToastEvent({
                        title: 'Error creating record',
                        message: error.body.message,
                        variant: 'error',
                    }),
                );
                console.log('error', JSON.stringify(error));
            });
    }
    


    @api show() {
        this.showModal = true;
    }

    handleDialogClose() {
        this.showModal = false;
    }   

    // @track selectedAccountId;
    // handleSelected(event){
    //     console.log(event.detail);
    //     this.selectedAccountId = event.detail;
    // }
}

Apex:
public with sharing class ContactTableProjectSecond {
    @AuraEnabled(cacheable=true)
    public static List<Contact> getContacts() {
        return [
            SELECT Id, FirstName, LastName, Phone, Email, Account.Name, AccountId, CreatedDate
            FROM Contact
        ];
    }
    
    @AuraEnabled(cacheable=true)
    public static List<Contact> searchContacts(String searchKey) {
        String searchKeyword = '%' + searchKey + '%';
        List<Contact> contacts = [
            SELECT Id, FirstName, LastName, Phone, Email, Account.Name, AccountId, CreatedDate
            FROM Contact
            WHERE Name LIKE :searchKeyword
        ];
        return contacts;        
    }

    @AuraEnabled
    public static void deleteContact(Id recordId) {   
        List<Contact> contact = [SELECT Id FROM Contact WHERE Id = :recordId];
        delete contact;   
   }
    
    @AuraEnabled
    public static Contact addContact(Contact con) {
        //Contact contact = new Contact(); 
        system.debug('con'+con);
    insert con;
        return con;
    } 
    
    @AuraEnabled(cacheable=true)
    public static List<account> getCustomLookupAccount(String actName) {
        List<account> accountLookupList =  new List<account>();
        System.debug('accountLookupList' + accountLookupList);
            if (actName != '') {
            String accountName = '%' + actName + '%';
            accountLookupList = [SELECT Id, Name FROM Account WHERE Name like:accountName];
            return accountLookupList;
            }
        return accountLookupList;
        }  
}
 
Hi All, i have a Custom field and the field name's character goes up to 80 characters so is there any way we can type out the Full name as of now the Char is Stopping at 40th character.
Hi Experts,
Today, I stuck in an issue. Actually I have a user xyz on that user's public group  Edit or Delete button is not showing. I want to add some more user in that group but edit button is not showing.
Could anyone help me that which permission I am missing.
Thanks In Advance
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;}
    }
}
 
Hi Peers,
I have a requirement. I want to fetch records from flow to lwc. we can do it by using apex but my manager was saying we can't use apex. we have to achieve it by flow.
Is there any way which we can achieve it?
You can refer any link or example.
Thanks In Advance
Hello Peers,
can someone help me to resolve this issue.I am not able to understand how to fix it.
Thanks In Advance
I get the following error when I try to save the code 
"Failed to save campingListItem.cmp: Invalid <aura:attribute> type: Camping_Item__c: Source"
<aura:component>
    <aura:attribute name="item" type="Camping_Item__c" required="true" />
    
    <p>Name:
        <ui:outputText value="{!v.item.Name}"/>
    </p>
    
    <p>Price:
        <lightning:formattedNumber value="{!v.item.Price__c}" style="currency"/>
    </p>
    
    <p>Quantity:
        <lightning:formattedNumber value="{!v.item.Quantity__c}" style="number"/>
    </p>

        
    <p>
        <lightning:input type="toggle"                            
                         label="Packed?"                           
                         name="Packed"                         
                         checked="{!v.item.Packed__c}" />
     </p> 
    
</aura:component>
  • October 30, 2021
  • Like
  • 0
I have one query and when im trying to iterate over it was showing the error.
[SELECT AccountSource,Account_Status__pc,Address_Verification_Status__pc,Agency_Code__c,Agency_Display_Name__c ,(
                                    SELECT Applicant__c,Appraisal_Value__c,Area__c,Account__c FROM Case) FROM Account WHERE Id IN: caseIdList];

I have this query while im writing like this :

                for(Account cs:acclist){
                                    
                                    if(cs.Case__r.Area__c!=null){
                    
                    htmlBody += '<tr><td style="border:1px solid red">' + 'CaseNumber' + '</td><td  style="border:1px solid ">' + cs.CaseNumber + '</td></tr>';
                }
How to Change CreatedDate Of Record In Test Class
I need to send  a information toast message in Lightning Web component(LWC) as Record Page is Loaded 
without any button click or change event

Below link has code but i dont need onclick ,it should show message by default
<lightning-button label="Show Info" onclick={showInfoToast}></lightning-button>

LWC recipes (https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.use_toast)

How to get this default Toast message in LWC?

Thanks for your help
Fiona
I Have QuickAction Button In Quick Action I'm using LWC Component
The Requirement Is it Showing On Record Detail Page in Lightning Experience But Not Showing On Community Site 
I am trying to create two identical contacts upon account creation. so far i have written below :
trigger IdenticalContacts on Account (after insert) {
    for (Account acc : Trigger.new){
    
        Contact con = new Contact();
        con.LastName = 'Monkey D';
        con.FirstName = 'Luffy';
        con.email = 'goldroger@gmail.com';
        con.AccountId = acc.id;
            
     }                           
}
I also wrote test class below but getting 0% code coverage:
@isTest
public class TestIndenticalContacts {
    
    @isTest static void createAccount(){
        Account acc = new Account();
        acc.Name = 'Salesforce';
        insert acc;
    }
}
Is the problem due to 'After Insert'?
 
Hi eveyone.
I need to display row number as seperate column with Row number as label in Custom LWC datatable. For every record should display serial number as seperate column with header. 
NOTE: I am not asking about show-row-number= true.
I should display row number as seperate field/column in table.

<c-custom-type-component
                            class="POdataTable slds-table_header-fixed_container slds-scrollable_x slds-border_top" 
                            key-field="Id" 
                            data={POrecords}
                            columns={columns} 
                            selected-rows={preSelectedRows} 
                            onrowaction={getPopUpInfo}
                            onpicklistchanged={tablePicklistChanged} 
                            onchangeofreturnqty={handelReturnQty}   
                            onselectedrow={handelSelectedRow}   
                            hide-checkbox-column                     
                        ></c-custom-type-component>

@track columns = [
{
            label: 'Row Number', cell: (row, index) => index + 1 
        }
]
If I am wrong PLEASE let me know. Thanks. 
Hi Experts,

I have a requirement, if a user clicks on a button it needs to open the record create form and a user can create a related object record on save. can anyone help me on this?
I want to show in <lightning output field> default values when there is no value in record field
I have an Account with Name "ATALANTE".
When I do a SOSL Query with filter "ATALANTA", the account is still returned.
It looks like SOSL does not search only exact matches.
User-added image

Can someone explain this?
I cannot find any article or documentation that explains this behavior, and I need to provide official explanation to my client.

Thank you
@AuraEnabled
    public static String getContentDetails(String recordId) {
        List<ContentDocumentLink> contentDocumentList = [SELECT ContentDocumentId, LinkedEntityId 
                                                            FROM   ContentDocumentLink 
                                                            WHERE  LinkedEntityId =: recordId];
        Set<Id> contentDocumentId = new Set<Id>();
            
        for(ContentDocumentLink cdl : contentDocumentList){
            contentDocumentId.add(cdl.ContentDocumentId);
        }
            
        List<ContentVersion> contentVersionList = [SELECT Id, VersionData, FileType, Title, FileExtension,Last_Updated_Date__c,
                                                    Comments__c,Last_Updated__c,Baseline_Category__c,CreatedBy.Name, ContentDocument.ContentSize,
                                                    CreatedDate, ContentDocumentId, ContentDocument.FileType
                                                    FROM   ContentVersion 
                                                    WHERE  ContentDocumentId IN : contentDocumentId order by Last_Updated_Date__c DESC ];
      
        return JSON.serialize(contentVersionList);
    }
This is my method for which i want to write test class
 
Hi,
Here is my script written in anonymous window to create record against opportuniyt for 3 month jan,feb,march but its not working please help me to solve




Map <Id, Opportunity> oppItems = new Map <Id, Opportunity>();
        
    list<ARRCalcualateOpportunity__c> Arropplist= new list<ARRCalcualateOpportunity__c>();
        list<Opportunity> opplist= new list<Opportunity>();
        
    for(opportunity opp:opplist){
       if (opp.StageName == 'Closed Won'&& opp.closeDate.month() >=1 && opp.closeDate.month() <=3 ) 
        {
          oppItems.put(opp.Id, opp);
        }
    }
    
    List<OpportunityLineItem> oliList = [select Id, Name, Product2Id, Product2.Family,opportunity.amount,opportunity.closedate from 
                                         OpportunityLineItem where OpportunityId IN:oppItems.keyset()];
        
        system.debug('oli'+ oliList);
        for(OpportunityLineItem oli :oliList)
        {
             for(Integer i =1;i<=12;i++)
                     {
                         if(oli.product2.family == 'software Recurring')
            {
              ARRCalcualateOpportunity__c arrOpp = new ARRCalcualateOpportunity__c();
             
                 arropp.name=string.valueOf(oli.opportunity.closedate);
                arropp.OpportunityArr__c= oli.OpportunityId;      
                arrOpp.Opportunity_Product__c= oli.product2Id;
                system.debug('arropp'+arropp);
              Arropplist.add(arropp);
            }
        }
        }
        
        if(Arropplist.size() >0){
          insert Arropplist;
            System.debug('arropp list'+arropplist);
        }
    
             


            
                 

                    
                    
Hi!
I have leadtable as in the image.

User-added image

I need get leads in input fields to save them automatically, not in columns. Please tell me how can I do that.

My code:
Html

<template>
    <lightning-card title="Leads">
        <lightning-layout multiple-rows="true" vertical-align="end">
           
            <lightning-layout-item size="12" padding="around-small">
                <lightning-datatable key-field="id" data={leads} columns={columns}>
                   
                </lightning-datatable>
                <lightning-input class="slds-p-around_medium" label="Name" name="leadName"
                    onchange={nameChangedHandler}></lightning-input>
                    <lightning-input class="slds-p-around_medium" label="Title" name="leadTitle"
                    onchange={titleChangedHandler}></lightning-input>
                <lightning-input class="slds-p-around_medium" label="Phone" type="phone" name="leadPhone"
                    onchange={phoneChangedHandler}></lightning-input>
                <br/>
            </lightning-layout-item>
           
        </lightning-layout>
    </lightning-card>
</template>

Js
import { LightningElement, wire } from 'lwc';
import getLeads from '@salesforce/apex/ProjectThree.getLeads';
import LEAD_OBJECT from '@salesforce/schema/Lead';
import NAME_FIELD from '@salesforce/schema/Lead.Title';
import TITLE_FIELD from '@salesforce/schema/Lead.Title';
import PHONE_FIELD from '@salesforce/schema/Lead.Phone';
const columns = [
    { label: 'Name', fieldName: 'recordLink', type: 'url',
        typeAttributes: {label: {fieldName: "LeadName"}, tooltip: "Name", linkify: true} },
    { label: 'Title', fieldName: 'Title', type: 'text', editable: true },
    { label: 'Phone', fieldName: 'Phone', type: 'text', editable: true }    
];
export default class LdsCreateRecord extends LightningElement {
    columns = columns;
    leads;
    lead = LEAD_OBJECT;
    myFields = [NAME_FIELD, TITLE_FIELD, PHONE_FIELD];
    strName;
    strTitle;
    strPhone;
    // Change Handlers.
    nameChangedHandler(event){
        this.strName = event.target.value;
    }
    titleChangedHandler(event){
        this.strAccountNumber = event.target.value;
    }
    phoneChangedHandler(event){
        this.strPhone = event.target.value;
    }
 
    @wire(getLeads)
    wiredLeads(value) {
        const {error, data} = value;
        if (data) {
            let leadData = JSON.parse(JSON.stringify(data));  
            leadData.forEach(record => {
                record.recordLink = "/" + record.Id;  
                record.LeadName = record.Name;
            });  
            this.leads = leadData;
        } else if (error) {
            this.error = error;
        }
    }
}

public with sharing class ProjectThree {
    @AuraEnabled(cacheable=true)
    public static List<Lead> getLeads() {
        List<Lead> leads = [
            SELECT Id, Name, Title, Phone
            FROM Lead         
            //WHERE Name Like 'Lisa%'
            Limit 3
        ];
        System.debug('leads = ' + leads);
        return leads;                
    }  
}   
Hi everyone!
I have contact table and need to get Id + Name as concatenation of Id '0032v000034aSJyAAM' and string 'Name' like on the image.

User-added image

Please tell me how can I do that.

Here is code:

Html:
<template>
    <lightning-card title="Contacts">
        <lightning-layout multiple-rows="true" vertical-align="end">
           
            <lightning-layout-item size="12" padding="around-small">
                <lightning-datatable key-field="id" data={contacts} columns={columns}></lightning-datatable>
            </lightning-layout-item>
           
        </lightning-layout>
    </lightning-card>
</template>

Js:
import { LightningElement , wire} from 'lwc';
import getContacts from '@salesforce/apex/Qqq.getContacts';
let N = 'Name';
const columns = [    
    { label: 'idName', fieldName: 'Id' + N, type: 'text' },
    { label: 'Name', fieldName: 'recordLink', type: 'url',
    typeAttributes: {label: {fieldName: "ContactName"}, tooltip: "Name", linkify: true} }  
];
export default class ContactTable extends LightningElement {
    columns = columns;
    contacts;
   
    @wire(getContacts)
    wiredContacts(value) {
        const {error, data} = value;
        if (data) {
            let contactData = JSON.parse(JSON.stringify(data));  
            contactData.forEach(record => {
                                record.recordLink = "/" + record.Id;  
                                record.ContactName = record.Name;
                        });  
            this.contacts = contactData;
        } else if (error) {
            this.error = error;
        }
    }
}

Apex:
public with sharing class Qqq {
    @AuraEnabled(cacheable=true)
    public static List<Lead> getLeads() {
        List<Lead> leads = [
            SELECT Id, Name, Title, Phone
            FROM Lead         
            WHERE Name Like 'Lisa%'
            Limit 3
        ];
        System.debug('leads = ' + leads);
        return leads;                
    }   
    
    @AuraEnabled(cacheable=true)
    public static List<Contact> getContacts() {
        List<Contact> contacts = [
            SELECT Id, Name
            FROM Contact     
            //WHERE LastName Like 'Apex%'
            Limit 3            
        ];        
        System.debug('contacts = ' + contacts);
        return contacts;    
    }   
}

 
how to insert new record in custom setting object field using Apex

<aura:attribute name="MapQuantity" type="Map" default="{'Id': , 'quantity':}"/>

How can I insert two values ​​obtained from two aura: attribute in the ID, Quantity fields of the map?
 
trigger PositionTrigger on Position__c (before insert,before update, before delete) {
    if(trigger.isBefore && (trigger.isInsert || trigger.isUpdate)){
        PositionTrigger_Handler.RecordTypeUpdate(Trigger.New);
    }
}
=============
public class PositionTrigger_Handler {
    Public Static void RecordTypeUpdate(List<Position__c> lstpos){
        Map<string,id> MappingRec = new Map<string, id>();
        List<RecordType> lstRec = [Select id, Developername from RecordType where SObjectType = 'Position__c'];
        for(RecordType rec: lstRec){
            MappingRec.put(rec.DeveloperName, rec.Id);
        }
        for(Position__c pos : lstpos){
            if(pos.Phase__c == 'Phase 1'){
                pos.RecordTypeId = MappingRec.get('Phase_1');
            }
            if(pos.Phase__c == 'Phase 2'){
                pos.RecordTypeId = MappingRec.get('Phase_2');
            }
            if(pos.Phase__c == 'Phase 3'){
                pos.RecordTypeId = MappingRec.get('Phase_3');
            }
        }
    }
}
=============================
@isTest
public class PositionTrigger_Handler_Test {
    
    Static testmethod void TestTrigger (){
        List<Position__c> lstpos = New List<Position__c> ();
        try{
            Position__C pos1 = New Position__C(Name='Test1', Amount__c=500, Phase__c='Phase 1');
            Position__C pos2 = New Position__C(Name='Test2', Amount__c=500, Phase__c='Phase 2');
            Position__C pos3 = New Position__C(Name='Test3', Amount__c=500, Phase__c='Phase 3');
            lstpos.add(pos1);
            lstpos.add(pos2);
            lstpos.add(pos3);
            insert lstpos;   
        }
        catch(DmlException e){
            system.debug('the following exception has occured: '+e.getMessage());
        }
        
    }
}
I have a custom mass update button for mass updating fields of records. But I want to hide it from certain users. How can I do it?
Hi!
I have lead table.
User-added image

I need that when I click on the name of the lead, it opens the detail page current Lead.
The link seems to work, but the detail page current Lead does not open. Please tell me how to fix it.

My code:
Html:
<template>
    <lightning-card title="Leads">
        <lightning-layout multiple-rows="true" vertical-align="end">
           
            <lightning-layout-item size="12" padding="around-small">
                <lightning-datatable key-field="id" data={leads} columns={columns}></lightning-datatable>
            </lightning-layout-item>
           
        </lightning-layout>
    </lightning-card>
</template>

Js:
import { LightningElement , wire} from 'lwc';
import getLeads from '@salesforce/apex/Qqq.getLeads';
const columns = [
    { label: 'Name', fieldName: 'Name', type: 'url',
    typeAttributes: {label: {fieldName: "Name"}, tooltip: "Name", linkify: true} },
    { label: 'Title', fieldName: 'Title', type: 'text' },
    { label: 'Phone', fieldName: 'Phone', type: 'text' }    
];
export default class LightningDatatableLWCExample extends LightningElement {
    columns = columns;
    leads;
   
    @wire(getLeads)
    wiredLeads(value) {
        const {error, data} = value;
        if (data) {
            let leadData = JSON.parse(JSON.stringify(data));  
            leadData.forEach(record => {
                            if (record.LeadId) {
                                record.recordLink = "/" + record.LeadId;  
                                record.LeadName = record.Lead.Name;
                            }
                        });  
            this.leads = leadData;
        } else if (error) {
            this.error = error;
        }
    }
}
 

I have two rows in data extension let us say Id and Name. The name can contain many Names but they are seperated by "," . For example:

Id      Name

1        A, B,C

So Using the query I want to acchive as below :

Id     Name

1        A

1        B 

1        C

 Set<Id> setInvalidWhatIdRecordTypes = new Set<Id>();
        Set<Id> setWhatIds = new Set<Id>();
        for(Event objEvent : listEvents)
        { 
            if(objEvent.WhatId != null){
                setWhatIds.add(objEvent.WhatId);
            }
        }
        for(Account acc : [SELECT Id
                           FROM Account
                           WHERE Id IN : setWhatIds
                           AND RecordType.DeveloperName != 'IndustriesBusiness']){
                               setInvalidWhatIdRecordTypes.add(acc.Id);
                           }
        if(!setInvalidWhatIdRecordTypes.isEmpty())
        {
            for(Event objEvent : listEvents)
            {
                if(objEvent.whatId != null && setInvalidWhatIdRecordTypes.contains(objEvent.whatId))
                {
                    objEvent.WhatId.addError('Account record type can only be business.');
                }
            }
        }
    }
Hi everyone.
I created a contact using lightning-input.
But I need to create a contact (and lookup search Account) using lightning-input-field. I сan't link html with js and Apex. Please tell me how can I do that. (I must use Apex).


My code with lightning-input that works:

Html:
<template>
    <lightning-card if:true={showModal}>
       <section role="dialog" tabindex="-1" aria-labelledby="modal-heading-01" aria-modal="true" class="slds-modal slds-fade-in-open">
            <div class="slds-modal__container">
                <lightning-button-icon class="slds-modal__close" title="Close" icon-name="utility:close" icon-class="slds-button_icon-inverse" onclick={handleDialogClose}></lightning-button-icon>
                <div class="slds-modal__header">
                    <h1 id="modal-heading-01" class="slds-modal__title slds-hyphenate">Create contact with custom lookup</h1>
                </div>
                <div class="slds-modal__content slds-p-around_medium" id="modal-content-id-1">                   
                    
                    
                    
                    <lightning-card title="New contact" icon-name="standard:contact">
                        <div class="slds-p-around_x-small">
                           
                            <lightning-input  type="text" label="Last name" value={rec.LNAME} onchange={handlelnameChange}></lightning-input>
                           
                            
                            <br/>
                            <lightning-button label="Save" onclick={handleClick}></lightning-button>
                        </div>
                    </lightning-card>


                </div>    
            </div>
        </section>
        <div class="slds-backdrop slds-backdrop_open" role="presentation"></div>
    </lightning-card>
</template>

Js:
import { LightningElement, api, wire, track } from 'lwc';
import LNAME_FIELD from '@salesforce/schema/Contact.LastName';
import insertContact from '@salesforce/apex/ContactTableProjectSecond.addContact';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import getContacts from '@salesforce/apex/ContactTableProjectSecond.getContacts';
import {refreshApex} from "@salesforce/apex";

export default class LwcNewContactUsingApexImperativecalling extends LightningElement {

    showModal = false;
    
    @track lname =LNAME_FIELD;
      
     rec={       
         LNAME:this.lname,        
      }

    @wire(getContacts)
    wiredCallback(result) {
        this._wiredResult = result;
    }

    handlelnameChange(event) {
        this.rec.LNAME = event.target.value;
        window.console.log("LNAME", this.rec.LNAME);
    }

    handleClick() {
        const contact = {
         
            LastName: this.rec.LNAME,
       
        }
        insertContact ({ con : contact })
            .then(() => {
                // this.rec={}; // Don't. You aren't clearing the value of rec properties, you're removing them. So everywhere you're using them you'll get an error because they will be now undefined properties.
            
                this.rec.LNAME = null;
               
                this.dispatchEvent(
                    new ShowToastEvent({
                        title: 'Success',
                        message: 'Contact created',
                        variant: 'success',
                    }),
                );
            })
            .catch((error) => {
                this.dispatchEvent(
                    new ShowToastEvent({
                        title: 'Error creating record',
                        message: error.body.message,
                        variant: 'error',
                    }),
                );
                console.log('error', JSON.stringify(error));
            });
    }

    @api show() {
        this.showModal = true;
    }

    handleDialogClose() {
        this.showModal = false;
    }   

    // @track selectedAccountId;
    // handleSelected(event){
    //     console.log(event.detail);
    //     this.selectedAccountId = event.detail;
    // }
}

Apex:
public with sharing class ContactTableProjectSecond {
    @AuraEnabled(cacheable=true)
    public static List<Contact> getContacts() {
        return [
            SELECT Id, FirstName, LastName, Phone, Email, Account.Name, AccountId, CreatedDate
            FROM Contact
        ];
    }
    
    @AuraEnabled(cacheable=true)
    public static List<Contact> searchContacts(String searchKey) {
        String searchKeyword = '%' + searchKey + '%';
        List<Contact> contacts = [
            SELECT Id, FirstName, LastName, Phone, Email, Account.Name, AccountId, CreatedDate
            FROM Contact
            WHERE Name LIKE :searchKeyword
        ];
        return contacts;        
    }

    @AuraEnabled
    public static void deleteContact(Id recordId) {   
        List<Contact> contact = [SELECT Id FROM Contact WHERE Id = :recordId];
        delete contact;   
   }
    
    @AuraEnabled
    public static Contact addContact(Contact con) {
        //Contact contact = new Contact(); 
        system.debug('con'+con);
    insert con;
        return con;
    } 
    
    @AuraEnabled(cacheable=true)
    public static List<account> getCustomLookupAccount(String actName) {
        List<account> accountLookupList =  new List<account>();
        System.debug('accountLookupList' + accountLookupList);
            if (actName != '') {
            String accountName = '%' + actName + '%';
            accountLookupList = [SELECT Id, Name FROM Account WHERE Name like:accountName];
            return accountLookupList;
            }
        return accountLookupList;
        }  
}

My code with lightning-input-field that doesn’t work:

Html:
<template>
    <lightning-card if:true={showModal} title={cardTitle}>
       <section role="dialog" tabindex="-1" aria-labelledby="modal-heading-01" aria-modal="true" class="slds-modal slds-fade-in-open">
            <div class="slds-modal__container">
                <lightning-button-icon class="slds-modal__close" title="Close" icon-name="utility:close" icon-class="slds-button_icon-inverse" onclick={handleDialogClose}></lightning-button-icon>
                <div class="slds-modal__header">
                    <h1 id="modal-heading-01" class="slds-modal__title slds-hyphenate">Create contact with custom lookup</h1>
                </div>
                <div class="slds-modal__content slds-p-around_medium" id="modal-content-id-1">                   
                    
                    
                    <lightning-card title={cardTitle}>                    
                    <div class="slds-m-around_medium">
                        <lightning-record-edit-form object-api-name="Contact">
                        
                            <lightning-input-field field-name="LastName">
                            </lightning-input-field> 
                            <lightning-input-field field-name="AccountId" value={recordId}>
                            </lightning-input-field>
                                <lightning-button
                                label="Save" onclick={handleClick}>
                                </lightning-button>
                        </lightning-record-edit-form>
                    </div>
                </lightning-card>


                </div>    
            </div>
        </section>
        <div class="slds-backdrop slds-backdrop_open" role="presentation"></div>
    </lightning-card>
</template>

Js:
import { LightningElement, api, wire, track } from 'lwc';
import LNAME_FIELD from '@salesforce/schema/Contact.Name';
//import LNAME_FIELD from '@salesforce/schema/Contact.LastName';
import insertContact from '@salesforce/apex/ContactTableProjectSecond.addContact';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import getContacts from '@salesforce/apex/ContactTableProjectSecond.getContacts';
import {refreshApex} from "@salesforce/apex";

export default class LwcNewContactUsingApexImperativecalling extends LightningElement {

    showModal = false;
 
    LastName = LNAME_FIELD;

    field={       
        LNAME:this.LastName,       
     }

    @api recordId;
  
    @wire(getContacts)
    wiredCallback(result) {
        this._wiredResult = result;
    }

    handlelnameChange(event) {
        this.field.LNAME = event.target.value;
        window.console.log("LNAME", this.field.LNAME);
    }

    handleClick(event) {
        console.log("handleClick", event);
        const contact = {
         
            LastName: this.field.LNAME,
       
        }
        insertContact ({ con : contact })
            .then(() => {
                // this.rec={}; // Don't. You aren't clearing the value of rec properties, you're removing them. So everywhere you're using them you'll get an error because they will be now undefined properties.
            
                this.field.LNAME = null;
               
                this.dispatchEvent(
                    new ShowToastEvent({
                        title: 'Success',
                        message: 'Contact created',
                        variant: 'success',
                    }),
                );
            })
            .catch((error) => {
                this.dispatchEvent(
                    new ShowToastEvent({
                        title: 'Error creating record',
                        message: error.body.message,
                        variant: 'error',
                    }),
                );
                console.log('error', JSON.stringify(error));
            });
    }
    


    @api show() {
        this.showModal = true;
    }

    handleDialogClose() {
        this.showModal = false;
    }   

    // @track selectedAccountId;
    // handleSelected(event){
    //     console.log(event.detail);
    //     this.selectedAccountId = event.detail;
    // }
}

Apex:
public with sharing class ContactTableProjectSecond {
    @AuraEnabled(cacheable=true)
    public static List<Contact> getContacts() {
        return [
            SELECT Id, FirstName, LastName, Phone, Email, Account.Name, AccountId, CreatedDate
            FROM Contact
        ];
    }
    
    @AuraEnabled(cacheable=true)
    public static List<Contact> searchContacts(String searchKey) {
        String searchKeyword = '%' + searchKey + '%';
        List<Contact> contacts = [
            SELECT Id, FirstName, LastName, Phone, Email, Account.Name, AccountId, CreatedDate
            FROM Contact
            WHERE Name LIKE :searchKeyword
        ];
        return contacts;        
    }

    @AuraEnabled
    public static void deleteContact(Id recordId) {   
        List<Contact> contact = [SELECT Id FROM Contact WHERE Id = :recordId];
        delete contact;   
   }
    
    @AuraEnabled
    public static Contact addContact(Contact con) {
        //Contact contact = new Contact(); 
        system.debug('con'+con);
    insert con;
        return con;
    } 
    
    @AuraEnabled(cacheable=true)
    public static List<account> getCustomLookupAccount(String actName) {
        List<account> accountLookupList =  new List<account>();
        System.debug('accountLookupList' + accountLookupList);
            if (actName != '') {
            String accountName = '%' + actName + '%';
            accountLookupList = [SELECT Id, Name FROM Account WHERE Name like:accountName];
            return accountLookupList;
            }
        return accountLookupList;
        }  
}
 
global class Batchclass44 implements Database.Batchable<sObject>{
    global static Database.QueryLocator start(Database.BatchableContext bc){
        return Database.getQueryLocator('SELECT Id, Background_Check_Done__c, LinkedIn_Profile__c, Verification_Status__c FROM Trainer_Master__c');
    }

    global void execute(Database.BatchableContext bc, List<Trainer_Master__c> t){
        List<Trainer_Master__c> a = new List<Trainer_Master__c>();
        for(Trainer_Master__c b: t){
            if(string.isblank(b.LinkedIn_Profile__c)){
                b.Verification_Status__c = 'Details Needed';
              
            }else {
               b.Verification_Status__c = ('No' == b.Background_Check_Done__c) ? 'Non Verified' : 'Verified';
            }

        }
    update t;
           
        }
 
    global void finish(Database.BatchableContext bc){ }
}
public class dfsmlwccontroller {
    @AuraEnabled(cacheable=true)
    public static List<Contact> getLwcContacts(string accountId){
        return [SELECT Id, Name FROM Contact WHERE accountId=:accountId];
    }
}
while running statement dfsmlwccontroller.getLwcContacts(); using debug open excute anonymos window getting

Line: 1, Column: 19
Method does not exist or incorrect signature: void getLwcContacts() from the type dfsmlwccontroller
Hi Team,
I have a below requirement. Lead record type field should be read only (uneditable) when:
- Lead Record type = Deal
- Lead record type  = Partner.

Please help me in acheiving this.
Thanks.
 
Hi every one,using lwc i am able to navigate to the detailpage but unable to open the new form when i click on new booking  getting errors in js file,please help me out.

Thanks in Advance.

html:
-----------

<template>
<!-- <lightning-card title="All Bookings">
<div class="slds-p-around_medium">
<template if:true={contacts} for:each={contacts} for:item="contact">
<li key={contact.Id}>
<a>{contact.Name}</a>
</li>
</template>
</div>
</lightning-card>-->
<lightning-card title="title of the component" class="slds-clearfix">
<div class="slds-p-around_medium">
<div class="slds-float_left"> <template if:true={bookings} for:each={bookings} for:item="booking">
<li key={booking.Id}>
<a target="_blank" onclick={handleOnClick} data-target-id={booking.Id}>{booking.Name}</a>
</li>
</template>
</div>
</div>
<div class="slds-clearfix">
<div class="slds-float_right">
<lightning-button label="New Booking" class="slds-m-left_x-small" onclick={navigatetorecordpage}></lightning-button>
</div>
</div>
</lightning-card>
</template>
-------
js:
import { LightningElement,api,track,wire } from 'lwc';
import getBookingList from '@salesforce/apex/taskexample.getBookingList';
 
import {NavigationMixin} from 'lightning/navigation';
 

   export default class lwcTask extends NavigationMixin (LightningElement) {  
    bookings;
error;


@wire(getBookingList) bookingDetails({error,data}){
if(data){
this.bookings=data;
}
else if(error){
this.error=error;
}
}


handleOnClick(event){
event.preventDefault();


let _recordId=event.target.dataset.targetId;

navigatetorecordpage( ){
this[NavigationMixin.Navigate]({
type: 'standard__recordPage',
attributes: {
recordId: _recordId,
objectApiName: 'Bokking__c',
actionName: 'New',
}
});
}
}
   }


 
  • March 21, 2022
  • Like
  • 0
Hi All,
UpcomingEvents query is fetching records  properly using Developer Console.But I am seeing just blank white card(LWC) only when I am clicking Home page.
Please help me!!!!!
User-added imageUser-added image
Apex Class:
--------------------------------------------------------------
public without sharing class EventListLWCService {
    @AuraEnabled(cacheable=true)
    public static List<Event__c> fetchUpcomingEvents(){
        List<Event__c> eventList=new List<Event__c>();
        try {
            eventList= [SELECT Id,Name,Name__c,CreatedDate,Event_Detail__c,Location__c,Location__r.Name,Event_Organizer__c,
                        Start_DateTime__c,End_Date_Time__c,Event_Organizer__r.Name,Event_Organizer__r.Email__c,Recurring__c,
                        Max_Seats__c,Status__c,Remaining_Seats__c,PeopleAttending__c
                        FROM Event__c
                        WHERE Start_DateTime__c >= Today AND Live__c = true
                        WITH SECURITY_ENFORCED
                        ];
           
        } catch (Exception e) {
            throw new AuraHandledException(e.getMessage());
        }
        return eventList;
    }
    @AuraEnabled(cacheable=true)
    public static List<Event__c> fetchPastEvents(){
        List<Event__c> eventList=new List<Event__c>();
        try {
            eventList= [SELECT Id,Name,Name__c,CreatedDate,Event_Detail__c,Location__c,Location__r.Name,Event_Organizer__c,
            Start_DateTime__c,End_Date_Time__c,Event_Organizer__r.Name,Event_Organizer__r.Email__c,Recurring__c,
            Max_Seats__c,Status__c,Remaining_Seats__c,PeopleAttending__c
            FROM Event__c
            WHERE Start_DateTime__c <= Today AND Live__c = true
            WITH SECURITY_ENFORCED
         ];
           
        } catch (Exception e) {
            throw new AuraHandledException(e.getMessage());
        }
        return eventList;
    }
   
}

HTML:
-----------------------------------------------
<template>
    <lightning-card variant="Narrow">
        <!--Upcoming Events-->
        <div class="slds-text-heading_large">Upcoming Events</div>
        <hr/>
        <lightning-layout multiple-rows>
            <lightning-layout-item size="12" padding="around-small" small-device-size="12" medium-device-size="6" large-device-size="4">
                <div class="slds-var-p-around_large">1
                </div>
            </lightning-layout-item>
            <lightning-layout-item  size="12" padding="around-small" small-device-size="12" medium-device-size="6" large-device-size="4">
                <div class="slds-var-p-around_large">2
                </div>
            </lightning-layout-item>
            <lightning-layout-item  size="12" padding="around-small" small-device-size="12" medium-device-size="6" large-device-size="4">
                <div class="slds-var-p-around_large">3
                </div>
            </lightning-layout-item>
            <template if:true={upComingEvents} for:each={upComingEvents} for:item="event" for:index="index">
            <lightning-layout-item key={event.Id} size="12" padding="around-small" small-device-size="12" medium-device-size="6" large-device-size="4">
                <div class="slds-var-p-around_large">
                <p>{event.Name__c}</p>
                <p>{event.Start_DateTime__c}</p>
                <p><lightning-formatted-rich-text value={event.Event_Detail__c}></lightning-formatted-rich-text></p>
                </div>
            </lightning-layout-item>
            </template>
        </lightning-layout>
        <!--Past Events-->
        <div class="slds-text-heading_large">Past Events</div>
        <hr/>
        <lightning-layout multiple-rows>
            <template if:true={pastEvents} for:each={pastEvents} for:item="event" for:index="index">
            <lightning-layout-item key={event.Id} size="12" padding="around-small" small-device-size="12" medium-device-size="6" large-device-size="4">
                <div class="slds-var-p-around_large">
                    <p>{event.Name__c}</p>
                    <p>{event.Start_DateTime__c}</p>
                    <p><lightning-formatted-rich-text value={event.Event_Detail__c}></lightning-formatted-rich-text></p>
            </div>
            </lightning-layout-item>
            </template>
        </lightning-layout>
    </lightning-card>
</template>
JavaScript file:
-----------------------------------------------------------------------
import { LightningElement, wire } from 'lwc';
import fetchUpcomingEvents from '@salesforce/apex/EventListLWCService.fetchUpcomingEvents';
import fetchPastEvents from '@salesforce/apex/EventListLWCService.fetchPastEvents';
export default class EventListComponent extends LightningElement {
    upcomingEvents;
    pastEvents;
    __errors;
    isSpinner=false;
    @wire(fetchUpcomingEvents)
    wiredUpcomingEventsData({ error, data }) {
      if (data) {
        console.log('Data', data);
        this.upcomingEvents=data;
      } else if (error) {
        console.error('Error:', error);
        this.upcomingEvents=undefined;
        this.__errors=error;
      }
    }
    @wire(fetchPastEvents)
    wiredPastEventsData({ error, data }) {
      if (data) {
        console.log('Data', data);
        this.fetchPastEvents=data;
      } else if (error) {
        console.error('Error:', error);
        this.fetchPastEvents=undefined;
        this.__errors=error;
      }
    }
}
Please let me know where i am doing wrong?

Thanks
 
  • February 02, 2022
  • Like
  • 0
Hello Developers,

I have created Field dependencies, Status picklist field is controlling and sub status picklist field is dependent. I have a requirement of showing path of both Status and Sub status picklist fields on the record page. I did that by Aura component but dependent picklist(sub status) is showing all the values on the path.

On path dependent picklist(sub status) should only show the values related to what user selects in controlling field (Status) means dependent picklist path should change and only show values on behalf of what we select in the controlling field.

Here is what I implemented: -

<aura:component implements="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" > <aura:attribute name="variant" type="String" default="non-linear"/> <aura:attribute name="hideUpdateButton" type="Boolean" default="true"/> <lightning:picklistPath aura:id="picklistPath" recordId="{!v.recordId}" variant="non-linear" picklistFieldApiName="Sub_Finance__c" onselect="{!c.handleSelect}"> </lightning:picklistPath> </aura:component>

({ handleSelect : function (component, event, helper) { var stepName = event.getParam("detail").value; var toastEvent = $A.get("e.force:showToast"); toastEvent.setParams({ "title": "Success!", "message": "Toast from " + stepName }); toastEvent.fire(); } }) 

Does anyone knows solution for this requirement?
I have a custom tab that displays a lighning component which on a click event allows a user to edit a record.
I am trying to listen for a save success on the e.force:editRecord and after much searching I found no solution as apparently there is no standard callback for the editRecord
https://trailblazer.salesforce.com/ideaView?id=0873A000000CQQiQAO
As per a few other suggestions I have added an handler for the force:showToast
This is working, albeit a hack, but the problem is as this is an application event it is constantly being listened for even if the custom tab isn't open.
Does anyone have any ideas how I can remedy this
<aura:handler event="force:showToast" action="{!c.handleToastEvent}"/>



handleToastEvent: function(component, event, helper){
        var toastMessageParams = event.getParams();
        var message = toastMessageParams.message;
        if(message.includes('Resource Placeholder') && message.includes('was saved')){
            var calendar = component.get('v._Calendar');
            var calendarEvent = event.getParam("calendarEvent")
            helper.fetchCalendarEvents(component, calendar, calendarEvent);
        }
    }

Many thanks,
Hi,
I have lightning components that displays images from ContentVersion as thumbnails and also links, when I click on the image its directly downloading the image but I would like it to open as preivew or open the image in a new tab/window. please advice.
below is the current line that displays image thumbnails with link to open big
<aura:iteration items="{!v.items}" var="content">
	       <a href="/sfc/servlet.shepherd/version/download/'+{!content.id}" target="_blank"> <img src="/sfc/servlet.shepherd/version/download/'+{!content.id}" width="100" height="100"/> </a>
	    </aura:iteration>

 
There is a weird scenario I'm facing while I try to bind the markup UI tags with lighting aura:attribute as type sObject (fields). I'm trying to bind data to sobject's fields for different lightning:input tags, For one sObject attribute the binding works perfect, but in the same way for another sObject the data is not getting bound. For Ex:
<aura:attribute name="student" type="JN_Student__c" access="global" default="{'sobjectType' : 'JN_Student__c'}" /> <lightning:input aura:id="requiredVal" name="lastName" label="Legal Last Name"value="{!v.student.JN_Last_Name__c}" maxlength="20" required="true"/>
above works perfectly and the data persists as I show/hide this section. WHEREAS for,

<aura:attribute name="insuranceInstance" type="JN_Insurance__c" access="global" default="{'sobjectType' : 'JN_Insurance__c'}" /> <lightning:input aura:id="requiredVal" name="lastName" label="Legal Last Name" value="{!v.insuranceInstance.Name}" maxlength="20" required="true"/>

the 'v.insuranceInstance.Name' doesn't persists its value.
Please reply if anyone knows/encounted the same.