• MOHAMMED BABA
  • NEWBIE
  • 10 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 5
    Replies
Hi Team,
i have lwc data table for the custom object Centre_Res__c now i want to show the pick list values for the field which i created Likelihood_Name_Central__c 
import { LightningElement,track,api,wire } from 'lwc';
import { getObjectInfo } from "lightning/uiObjectInfoApi";
import { getPicklistValues } from 'lightning/uiObjectInfoApi';
import Centre_Object from '@salesforce/schema/Centre_Res__c';

const columns = [
{
        label: 'Likelihood Ranges Name',
        fieldName: 'Likelihood_Name_Central__c', // Update this fieldName based on your data structure
        editable: true,
        hideDefaultActions: true,
        type: 'combobox', // Specify that this column contains a combobox
        typeAttributes: {
            placeholder: 'Select Likelihood',
            options: '$likelihoodPicklistValues', // Bind to your picklist values
            value: 'selectedLikelihood' // Bind to the selected value
        }
    },
];  after export  
 @api recordId;
    @track likelihoodPicklistValues = [];
    @track recordTypeId;   



@wire(getObjectInfo, { objectApiName: Centre_Object })
   likelihoodObjectMetadata({ error, data }) {
       if (data) {console.log('data'+JSON.stringify(data));
           this.recordTypeId = data; // Set the recordTypeId here based on your use case
           console.log(' this.recordTypeId-->'+JSON.stringify( this.recordTypeId));
       }
   }
   // Fetch picklist values with the specific recordTypeId
   @wire(getPicklistValues, {
       recordTypeId: '$recordTypeId', // Use the custom attribute for recordTypeId
       fieldApiName: 'Centre_Res__c.Likelihood_Name_Central__c'
   })
   wiredPicklistValues({ error, data }) {
       if (data) {
           this.likelihoodPicklistValues = data.values;
           console.log('Picklist Values: ' + JSON.stringify(this.likelihoodPicklistValues));
       } else if (error) {
           console.error('Error fetching picklist values: ' + JSON.stringify(error));
       }
   }
HTML: 
 <template if:true={dataTableValue}>
        <div  class="myTable">
            <lightning-combobox
            label="Likelihood Ranges Name"
            value={selectedLikelihood}
            options={likelihoodPicklistValues}
            onchange={handleLikelihoodChange}
        ></lightning-combobox>
        <lightning-datatable data={dataTableValue} columns={columns} key-field="Id" hide-checkbox-column
        aria-selected="true" onsave={handleSaveDataTable} draft-values={saveDraftValue}
        onrowaction={handleRowAction}>
       
    </lightning-datatable>   can you please help with the exact code or if you have any document where i can see the picklist for custom object 
I am using below code I want to display Info button or onhover on one of the custom field inside the lwc data table but not able to achieve this ,kindly guide me <template>
    <div class="slds-m-around_x-small">
        <lightning-card title="Connect With Stackholders" icon-name="standard:channel_program_history">
            <lightning-layout multiple-rows>
                <lightning-layout-item size="12" small-device-size="3" medium-device-size="3" large-device-size="3"
                    padding="around-small">
                    <lightning-combobox class="priorityAlign" label="Risk Id" name="input2"
                        placeholder={selectDepartment} options={riskIdsBasedOnRegion} dropdown-alignment="auto"
                        onchange={handleChangeRiskId}></lightning-combobox>
                </lightning-layout-item>
                <lightning-layout-item size="12" small-device-size="2" medium-device-size="2" large-device-size="2"
                    padding="around-small">
                    <lightning-input label="Risk Name" type="text" value={riskNameValue} autocomplete="off" disabled></lightning-input>
                </lightning-layout-item>

                <lightning-layout-item size="12" small-device-size="2" medium-device-size="2" large-device-size="2"
                    padding="around-small">
                    <lightning-input label="Region" type="text" value={regionValue} disabled></lightning-input>
                </lightning-layout-item>
                <lightning-layout-item size="12" small-device-size="3" medium-device-size="3" large-device-size="3"
                    padding="around-small">
                    <lightning-dual-listbox class="priorityAlign" label="Department" name="input2"
                        placeholder={selectDepartment} options={listOfDepartment} dropdown-alignment="auto"
                        onchange={handleChangeDepartment}></lightning-dual-listbox>
                </lightning-layout-item>

                <lightning-layout-item size="12" small-device-size="2" medium-device-size="2" large-device-size="2"
                    padding="around-small">
                    <div class="slds-m-top_large">
                        <lightning-button variant="success" label="Submit" onclick={handleSave}></lightning-button>
                    </div>
                   
                </lightning-layout-item>
            </lightning-layout>
           
       
    </lightning-card>
</div>
       
    <template if:true={dataTableValue}>
        <lightning-datatable data={dataTableValue} columns={columns} key-field="Id" hide-checkbox-column
            aria-selected="true" onsave={handleSaveDataTable} draft-values={saveDraftValue}
            onrowaction={handleRowAction}>
            <template for:each={dataTableValue} for:item="record">
                <tr key={record.Id}>
                    <!-- ... Other columns ... -->
                    <td data-label="Total Financial Impact" onmouseover={showValue} onmouseout={hideValue}>
                        <template if:true={record.Total_Financial_Impact__c}>
                            <div class="value-container">
                                {record.Total_Financial_Impact__c}
                                <div class="info-button" data-id={record.Id} onclick={showInfo}>i</div>
                                <template if:true={shouldRenderInfo}>
                                    <div class="info-tooltip">Total: {calculatedTotalFinancialImpact}</div>
                                </template>
                            </div>
                        </template>
                        <template if:false={record.Total_Financial_Impact__c}>
                            <div class="value-container">
                                {record.Total_Financial_Amount__c}
                            </div>
                        </template>
                    </td>
                </tr>
            </template>
        </lightning-datatable>
    </template>
   
</template>
 @track showTooltip = false;
    @track selectedRecordId = null;
    @track totalFinancialImpact = 0;
    get shouldRenderInfo() {
        return this.selectedRecordId !== null;
    }
    get calculatedTotalFinancialImpact() {
        if (this.dataTableValue && this.dataTableValue.length > 0) {
            this.totalFinancialImpact = this.dataTableValue.reduce(
                (sum, record) => sum + record.Total_Financial_Impact__c,
                0
            );
        } else {
            this.totalFinancialImpact = 0;
        }
        return this.totalFinancialImpact;
    }
    // ... other methods ...
    // Update the showValue and showInfo methods to handle the tooltip display
    showValue(event) {
        const recordId = event.target.dataset.id;
        this.selectedRecordId = recordId;
        this.showTooltip = true;
    }
    showInfo(event) {
        const recordId = event.target.dataset.id;
        this.selectedRecordId = recordId;
        this.showTooltip = true;
    }
    hideValue() {
        this.selectedRecordId = null;
        this.showTooltip = false;
    }   
  1. Create a new field (Commission) on Opportunity object and it should automatically calculate the commission based on the below conditions:
  • If Lead Source is Web and Amount is greater than 1,000 then the commission is 2% of the Amount.
Apex class ----
public without sharing class AnnouncementController    {
    @AuraEnabled(cacheable=true)
    public static List<Object_A> getNews(){
        List<user> user=  [Select Id,c_User_Country__c,ContactId,  isPortalEnabled from User where id= :UserInfo.getUserId()];
        System.debug('user->'+user);
        List<Object_A> newsRecords = new List<Object_A>();
        List<Object_A> nonDashboardRecords = new List<Object_A>();
        String userCountry =user[0].c_User_Country__c;
        String custType;
        Contact cont = getContact(UserInfo.getUserId());
        if (cont!=null){
            custType= cont.Account.Sub_Type__c;
            for(Object_A jc: [SELECT id,name,Title__c,Youtube_Video_Id__c, Image_URL__c, CreatedDate ,CreatedBy.Name,Is_Dashboard_Content__c  from Object_A where                           
                                    ((Start_Date__c <= TODAY AND End_Date__c >= TODAY) OR (Start_Date__c = null AND End_Date__c = null))
                                    AND (Country__c = :userCountry OR Country__c = 'Global') AND Customer_Type__c INCLUDES (:custType) AND Type__C='News' ORDER BY Sequence__c,CreatedDate ASC]){
                                        if(jc.Is_Dashboard_Content__c){
                                            newsRecords.add(jc);   
                                        }else{
                                            nonDashboardRecords.add(jc);  
                                        }    }
                                   
            newsRecords.addAll(nonDashboardRecords);
        }
        if (newsRecords==null || newsRecords.size()==0){
            userCountry = 'Other';
            if (cont==null){
                for(Object_A jc: [SELECT id,name,Title__c,Youtube_Video_Id__c, Image_URL__c, CreatedDate ,CreatedBy.Name,Is_Dashboard_Content__c  from Object_A where
                                        ((Start_Date__c <= TODAY AND End_Date__c >= TODAY) OR (Start_Date__c = null AND End_Date__c = null) )
                                        AND (Country__c = :userCountry OR Country__c = 'Global') AND Type__C='News' ORDER BY Sequence__c,CreatedDate ASC]){
                                            if(jc.Is_Dashboard_Content__c){
                                                newsRecords.add(jc);   
                                            }else{
                                                nonDashboardRecords.add(jc);  
                                            }     
                                        }
                newsRecords.addAll(nonDashboardRecords);
            }else{
                for(Object_A jc: [SELECT id,name,Title__c,Youtube_Video_Id__c, Image_URL__c, CreatedDate ,CreatedBy.Name,Is_Dashboard_Content__c  from Object_A where
                                        ((Start_Date__c <= TODAY AND End_Date__c >= TODAY) OR (Start_Date__c = null AND End_Date__c = null))
                                        AND (Country__c = :userCountry OR Country__c = 'Global') AND Customer_Type__c INCLUDES (:custType) AND Type__C='News' ORDER BY Sequence__c,CreatedDate ASC]){
                                            if(jc.Is_Dashboard_Content__c){
                                                newsRecords.add(jc);   
                                            }else{
                                                nonDashboardRecords.add(jc);  
                                            }     
                                        }
                newsRecords.addAll(nonDashboardRecords);
            }
        }
        system.debug('newsRecords :::'+ newsRecords);
        return newsRecords;
    }

 

Apex class
global class ModelLevel{
global static String getfunction(){
      String fpmsg;
      User usr = [select Id,Name,accountid,c_User_Country__c From User where Id = :UserInfo.getUserId() LIMIT 1];
 List<ObjectA__c> rcmsg = new List<ObjectA__c>();
      rcmsg  =[SELECT body__c from ObjectA__c where Type__C='homemessage' AND Country__c=:usr.c_User_Country__c  LIMIT 1];
           if(rcmsg!=null && !rcmsg.isEmpty() ){
               if(rcmsg[0].body__c!=null && rcmsg[0].body__c!=''){
                   fpmsg =rcmsg[0].body__c;
                    }
               else{
                   rcmsg =[SELECT id,name,Title__c,body__c from ObjectA__c where Type__C='homemessage' AND Country__c ='Global' LIMIT 1];
                                                fpmsg= rcmsg[0].body__c;
     }
          }
               else{
               rcmsg =[SELECT id,name,Title__c,body__c from ObjectA__c where Type__C='homemessage' AND Country__c ='Global' LIMIT 1];
                              fpmsg= rcmsg[0].body__c;
      }
      return fpmsg.unescapeHtml4();  
    }
########################################################
Test class

@isTest
Global class Modelleveltest
{

 private static testMethod void test_getfunction (){
        Account acc = CreateTestDataUtility.createAccount();
        Contact con = CreateTestDataUtility.createContact(acc);
        Contact con1 = CreateTestDataUtility.createContact(acc);
                Profile p = [SELECT Id FROM Profile WHERE Name = 'Sales User' LIMIT 1];
                 User localUser= new User
                profileId = p.id,
                username = 'Test33@test.com.test',
                email = 'Test33@test.com.test',
                emailencodingkey = 'UTF-8',
                localesidkey = 'en_US',
                languagelocalekey = 'en_US',
                timezonesidkey='America/Los_Angeles',
                alias='test22',
                lastname='Testing22',
                contactId=con.id,
                country =  'Turkey',
                Geographic_Region__c='Europe',                  
                c_User_Country__c = 'Turkey',
                User_Region__c = 'Turkey'
            );
        insert localUser;
       
        User TestUser= new User(
                          
                profileId = p.id,
                username = '23@test.com.test',
                email = '23@test.com.test',
                emailencodingkey = 'UTF-8',
                localesidkey = 'en_US',
                languagelocalekey = 'en_US',
                timezonesidkey='America/Los_Angeles',
                alias='newtest3',
                lastname='Testing3',
                contactId=con1.id,
                country = 'France',
                Geographic_Region__c='Europe',                   
                c_User_Country__c = 'France',
                User_Region__c = 'France'
            );
               insert TestUser;
List< ObjectA__c > Newval = new List< ObjectA__c >();
ObjectA__c usr1 = new ObjectA__c (Name='Content11',Country__c='Turkey',Customer_Type__c='Distributor',Title__c='Test Content',Body__c='Testconentnew',Type__c=' homemessage ');
Newval.add(usr1);
ObjectA__c usr2 = new ObjectA__c (Name='Content22',Country__c='Global',Customer_Type__c='Distributor',Title__c='Test Content test',Body__c='TestContentnewmsg',Type__c=' homemessage ');
Newval.add(usr2);
insert Newval;
        Test.StartTest();
        System.runAs(localUser){
  ModelLevel. getfunction ();
        }
                System.runAs(TestUser){
  ModelLevel. getfunction ();
                }
            Test.StopTest();
        }
}




      
 
I am using below code I want to display Info button or onhover on one of the custom field inside the lwc data table but not able to achieve this ,kindly guide me <template>
    <div class="slds-m-around_x-small">
        <lightning-card title="Connect With Stackholders" icon-name="standard:channel_program_history">
            <lightning-layout multiple-rows>
                <lightning-layout-item size="12" small-device-size="3" medium-device-size="3" large-device-size="3"
                    padding="around-small">
                    <lightning-combobox class="priorityAlign" label="Risk Id" name="input2"
                        placeholder={selectDepartment} options={riskIdsBasedOnRegion} dropdown-alignment="auto"
                        onchange={handleChangeRiskId}></lightning-combobox>
                </lightning-layout-item>
                <lightning-layout-item size="12" small-device-size="2" medium-device-size="2" large-device-size="2"
                    padding="around-small">
                    <lightning-input label="Risk Name" type="text" value={riskNameValue} autocomplete="off" disabled></lightning-input>
                </lightning-layout-item>

                <lightning-layout-item size="12" small-device-size="2" medium-device-size="2" large-device-size="2"
                    padding="around-small">
                    <lightning-input label="Region" type="text" value={regionValue} disabled></lightning-input>
                </lightning-layout-item>
                <lightning-layout-item size="12" small-device-size="3" medium-device-size="3" large-device-size="3"
                    padding="around-small">
                    <lightning-dual-listbox class="priorityAlign" label="Department" name="input2"
                        placeholder={selectDepartment} options={listOfDepartment} dropdown-alignment="auto"
                        onchange={handleChangeDepartment}></lightning-dual-listbox>
                </lightning-layout-item>

                <lightning-layout-item size="12" small-device-size="2" medium-device-size="2" large-device-size="2"
                    padding="around-small">
                    <div class="slds-m-top_large">
                        <lightning-button variant="success" label="Submit" onclick={handleSave}></lightning-button>
                    </div>
                   
                </lightning-layout-item>
            </lightning-layout>
           
       
    </lightning-card>
</div>
       
    <template if:true={dataTableValue}>
        <lightning-datatable data={dataTableValue} columns={columns} key-field="Id" hide-checkbox-column
            aria-selected="true" onsave={handleSaveDataTable} draft-values={saveDraftValue}
            onrowaction={handleRowAction}>
            <template for:each={dataTableValue} for:item="record">
                <tr key={record.Id}>
                    <!-- ... Other columns ... -->
                    <td data-label="Total Financial Impact" onmouseover={showValue} onmouseout={hideValue}>
                        <template if:true={record.Total_Financial_Impact__c}>
                            <div class="value-container">
                                {record.Total_Financial_Impact__c}
                                <div class="info-button" data-id={record.Id} onclick={showInfo}>i</div>
                                <template if:true={shouldRenderInfo}>
                                    <div class="info-tooltip">Total: {calculatedTotalFinancialImpact}</div>
                                </template>
                            </div>
                        </template>
                        <template if:false={record.Total_Financial_Impact__c}>
                            <div class="value-container">
                                {record.Total_Financial_Amount__c}
                            </div>
                        </template>
                    </td>
                </tr>
            </template>
        </lightning-datatable>
    </template>
   
</template>
 @track showTooltip = false;
    @track selectedRecordId = null;
    @track totalFinancialImpact = 0;
    get shouldRenderInfo() {
        return this.selectedRecordId !== null;
    }
    get calculatedTotalFinancialImpact() {
        if (this.dataTableValue && this.dataTableValue.length > 0) {
            this.totalFinancialImpact = this.dataTableValue.reduce(
                (sum, record) => sum + record.Total_Financial_Impact__c,
                0
            );
        } else {
            this.totalFinancialImpact = 0;
        }
        return this.totalFinancialImpact;
    }
    // ... other methods ...
    // Update the showValue and showInfo methods to handle the tooltip display
    showValue(event) {
        const recordId = event.target.dataset.id;
        this.selectedRecordId = recordId;
        this.showTooltip = true;
    }
    showInfo(event) {
        const recordId = event.target.dataset.id;
        this.selectedRecordId = recordId;
        this.showTooltip = true;
    }
    hideValue() {
        this.selectedRecordId = null;
        this.showTooltip = false;
    }   
  1. Create a new field (Commission) on Opportunity object and it should automatically calculate the commission based on the below conditions:
  • If Lead Source is Web and Amount is greater than 1,000 then the commission is 2% of the Amount.

Apex class
global class ModelLevel{
global static String getfunction(){
      String fpmsg;
      User usr = [select Id,Name,accountid,c_User_Country__c From User where Id = :UserInfo.getUserId() LIMIT 1];
 List<ObjectA__c> rcmsg = new List<ObjectA__c>();
      rcmsg  =[SELECT body__c from ObjectA__c where Type__C='homemessage' AND Country__c=:usr.c_User_Country__c  LIMIT 1];
           if(rcmsg!=null && !rcmsg.isEmpty() ){
               if(rcmsg[0].body__c!=null && rcmsg[0].body__c!=''){
                   fpmsg =rcmsg[0].body__c;
                    }
               else{
                   rcmsg =[SELECT id,name,Title__c,body__c from ObjectA__c where Type__C='homemessage' AND Country__c ='Global' LIMIT 1];
                                                fpmsg= rcmsg[0].body__c;
     }
          }
               else{
               rcmsg =[SELECT id,name,Title__c,body__c from ObjectA__c where Type__C='homemessage' AND Country__c ='Global' LIMIT 1];
                              fpmsg= rcmsg[0].body__c;
      }
      return fpmsg.unescapeHtml4();  
    }
########################################################
Test class

@isTest
Global class Modelleveltest
{

 private static testMethod void test_getfunction (){
        Account acc = CreateTestDataUtility.createAccount();
        Contact con = CreateTestDataUtility.createContact(acc);
        Contact con1 = CreateTestDataUtility.createContact(acc);
                Profile p = [SELECT Id FROM Profile WHERE Name = 'Sales User' LIMIT 1];
                 User localUser= new User
                profileId = p.id,
                username = 'Test33@test.com.test',
                email = 'Test33@test.com.test',
                emailencodingkey = 'UTF-8',
                localesidkey = 'en_US',
                languagelocalekey = 'en_US',
                timezonesidkey='America/Los_Angeles',
                alias='test22',
                lastname='Testing22',
                contactId=con.id,
                country =  'Turkey',
                Geographic_Region__c='Europe',                  
                c_User_Country__c = 'Turkey',
                User_Region__c = 'Turkey'
            );
        insert localUser;
       
        User TestUser= new User(
                          
                profileId = p.id,
                username = '23@test.com.test',
                email = '23@test.com.test',
                emailencodingkey = 'UTF-8',
                localesidkey = 'en_US',
                languagelocalekey = 'en_US',
                timezonesidkey='America/Los_Angeles',
                alias='newtest3',
                lastname='Testing3',
                contactId=con1.id,
                country = 'France',
                Geographic_Region__c='Europe',                   
                c_User_Country__c = 'France',
                User_Region__c = 'France'
            );
               insert TestUser;
List< ObjectA__c > Newval = new List< ObjectA__c >();
ObjectA__c usr1 = new ObjectA__c (Name='Content11',Country__c='Turkey',Customer_Type__c='Distributor',Title__c='Test Content',Body__c='Testconentnew',Type__c=' homemessage ');
Newval.add(usr1);
ObjectA__c usr2 = new ObjectA__c (Name='Content22',Country__c='Global',Customer_Type__c='Distributor',Title__c='Test Content test',Body__c='TestContentnewmsg',Type__c=' homemessage ');
Newval.add(usr2);
insert Newval;
        Test.StartTest();
        System.runAs(localUser){
  ModelLevel. getfunction ();
        }
                System.runAs(TestUser){
  ModelLevel. getfunction ();
                }
            Test.StopTest();
        }
}