Play Games

Search This Blog

Monday, December 21, 2020

convert date to datetime in apex salesforce - Salesforce Globe For You

 convert date to datetime in apex salesforce  - Salesforce Globe For You 

Example:

Date dtTodayDate = System.Today();

Datetime dtTodayDateTime = datetime.newInstance(dtTodayDate.year(), dtTodayDate.month(),dtTodayDate.day());

system.debug('Date in DateTime:'+dtTodayDateTime);

Output:



Display date in MM/DD/YYYY format in apex salesforce - Salesforce Globe For You

 Display date in MM/DD/YYYY format in apex salesforce  - Salesforce Globe For You 

Solution: First convert date to dateTime field and then use format() to display in the required format.

Example:

Date dtTodayDate = System.Today();

Datetime dtTodayDateTime = datetime.newInstance(dtTodayDate.year(), dtTodayDate.month(),dtTodayDate.day());

string strDate = dtTodayDateTime.format('MM/dd/yyyy');

system.debug('Date in MM/DD/YYYY format:'+strDate);

Output:



Monday, December 14, 2020

How to display/show an error message at the respective field through trigger salesforce? - Salesforce Globe For You

 How to display/show an error message at the respective field through trigger salesforce?  - Salesforce Globe For You 

Problem: Assume while inserting Lead record,in case if Email field of Lead is empty ,need to display an error Message 'Please Enter Email' below the Email field itself.

Solution: use addError() method at it's respective record field to display Error message like this objLead.Email.addError('Please Enter Email'); where Email is field where error message to be displayed.

Example:

trigger ErrorMessageAtFieldLevel on Lead (before insert) {

    for(Lead objLead :trigger.new) {

        if(String.isBlank(objLead.Email)) {

            objLead.Email.addError('Please Enter Email');

        }

    }

}

Output: when you try creating a new Lead record without entering Email,it will through an error message at the Email field as shown below.



Wednesday, December 9, 2020

Dynamic multiple tabs in lwc Salesforce - Salesforce Globe For You

 Dynamic multiple tabs in lwc Salesforce  - Salesforce Globe For You 

LWC Component: dynamicTabsInLWC

dynamicTabsInLWC.html

<template>

    <lightning-tabset>

        <template for:each={lstTabs} for:item="tab">

            <lightning-tab label={tab.Name} key={tab.Name}>

                {tab.Id}

            </lightning-tab>

        </template>

    </lightning-tabset>

</template>

dynamicTabsInLWC.js

import { LightningElement,track } from 'lwc';

export default class DynamicTabsInLWC extends LightningElement {

    @track lstTabs = [

        {

            Id: 1,

            Name: 'Tab 1'

        },

        {

            Id: 2,

            Name: 'Tab 2'

        },

        {

            Id: 3,

            Name: 'Tab 3'

        },

    ];

    

}

dynamicTabsInLWC.js-meta.xml

<?xml version="1.0" encoding="UTF-8"?>

<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">

    <apiVersion>48.0</apiVersion>

    <isExposed>true</isExposed>

    <targets>

        <target>lightning__RecordPage</target>

        <target>lightning__AppPage</target>

        <target>lightning__HomePage</target>

    </targets>

</LightningComponentBundle>

Note:dynamically populate lstTabs variaable as per your requirement.

Output: