December 31, 2020

Custom sorting with Up and Down Arrow using LWC in Salesforce

Sample Code:

HTML:
<template> 
    <div class="slds-box slds-theme--default"> 
        <div class="slds-text-color_inverse slds-text-heading_large" style="padding:0.5rem;background:#16325c">        
            Accounts
        </div>
        <table class="slds-table slds-table_cell-buffer slds-table_bordered slds-table_striped">
            <thead>
                <tr class="slds-line-height_reset">
                    <th class="" scope="col">
                        <a class="slds-th__action slds-text-link_reset" href="javascript:void(0);" role="button" tabindex="0" onclick={sortRecs} name="Name">
                            Account Name
                            <lightning-icon icon-name="utility:arrowup" size="x-small" if:true={nameUpBool}></lightning-icon>
                            <lightning-icon icon-name="utility:arrowdown" size="x-small" if:true={nameDWBool}></lightning-icon>
                        </a>
                    </th>
                    <th class="" scope="col">
                        <a class="slds-th__action slds-text-link_reset" href="javascript:void(0);" role="button" tabindex="0" onclick={sortRecs} name="AccountNumber">
                            Account Number
                            <lightning-icon icon-name="utility:arrowup" size="x-small" if:true={noUpBool}></lightning-icon>
                            <lightning-icon icon-name="utility:arrowdown" size="x-small" if:true={noDWBool}></lightning-icon>
                        </a>
                    </th>
                    <th class="" scope="col">
                        <a class="slds-th__action slds-text-link_reset" href="javascript:void(0);" role="button" tabindex="0" onclick={sortRecs} name="Industry">
                            Industry
                            <lightning-icon icon-name="utility:arrowup" size="x-small" if:true={indUpBool}></lightning-icon>
                            <lightning-icon icon-name="utility:arrowdown" size="x-small" if:true={indDWBool}></lightning-icon>
                        </a>
                    </th>
                    <th class="" scope="col">
                        <a class="slds-th__action slds-text-link_reset" href="javascript:void(0);" role="button" tabindex="0" onclick={sortRecs} name="Rating">
                            Rating
                            <lightning-icon icon-name="utility:arrowup" size="x-small" if:true={rateUpBool}></lightning-icon>
                            <lightning-icon icon-name="utility:arrowdown" size="x-small" if:true={rateDWBool}></lightning-icon>
                        </a>
                    </th>
                    <th class="" scope="col">
                        <a class="slds-th__action slds-text-link_reset" href="javascript:void(0);" role="button" tabindex="0" onclick={sortRecs} name="Type">
                            Type
                            <lightning-icon icon-name="utility:arrowup" size="x-small" if:true={typeUpBool}></lightning-icon>
                            <lightning-icon icon-name="utility:arrowdown" size="x-small" if:true={typeDWBool}></lightning-icon>
                        </a>
                    </th>
                    <th class="" scope="col">
                        <a class="slds-th__action slds-text-link_reset" href="javascript:void(0);" role="button" tabindex="0" onclick={sortRecs} name="Phone">
                            Phone
                            <lightning-icon icon-name="utility:arrowup" size="x-small" if:true={phoneUpBool}></lightning-icon>
                            <lightning-icon icon-name="utility:arrowdown" size="x-small" if:true={phoneDWBool}></lightning-icon>
                        </a>
                    </th>
                </tr>
            </thead>
            <tbody>
                <template iterator:it={records}>
                    <tr class="slds-hint-parent" key = {it.value.Id}>
                        <td data-label="Account Name">
                            <div class="slds-cell-wrap">{it.value.Name}</div>
                        </td>
                        <td data-label="Account Number">
                            <div class="slds-cell-wrap">{it.value.AccountNumber}</div>
                        </td>
                        <td data-label="Industry">
                            <div class="slds-cell-wrap">{it.value.Industry}</div>
                        </td>
                        <td data-label="Rating">
                            <div class="slds-cell-wrap">{it.value.Rating}</div>
                        </td>
                        <td data-label="Type">
                            <div class="slds-cell-wrap">{it.value.Type}</div>
                        </td>
                        <td data-label="Phone">
                            <div class="slds-cell-wrap">{it.value.Phone}</div>
                        </td>
                    </tr>
                </template>
            </tbody>
        </table>
    </div>
</template>

JavaScript:
import { LightningElement, wire } from 'lwc'; 
import fetchAccounts from '@salesforce/apex/AccountController.fetchAccounts';

export default class Sample extends LightningElement {

    records;
    sortedColumn;
    sortedDirection;
    nameUpBool;
    nameDWBool;
    noUpBool;
    noDWBool;
    indUpBool;
    indDWBool;
    rateUpBool;
    rateDWBool;
    typeUpBool;
    typeDWBool;
    phoneUpBool;
    phoneDWBool;

    @wire( fetchAccounts )  
    wiredAccount( { error, data } ) {

        if (data) {

            this.records = data;
            this.initialRecords = data;
            this.error = undefined;
            this.sortedColumn = "Name";
            this.sortRecs();

        } else if ( error ) {

            this.error = error;
            this.initialRecords = undefined;
            this.records = undefined;

        }

    }  

    sortRecs( event ) {

        this.nameUpBool = false;
        this.nameDWBool = false;
        this.noUpBool = false;
        this.noDWBool = false;
        this.indUpBool = false;
        this.indDWBool = false;
        this.rateUpBool = false;
        this.rateDWBool = false;
        this.typeUpBool = false;
        this.typeDWBool = false;
        this.phoneUpBool = false;
        this.phoneDWBool = false;
        let colName = event ? event.target.name : undefined;
        console.log( 'Column Name is ' + colName );

        if ( this.sortedColumn === colName )
            this.sortedDirection = ( this.sortedDirection === 'asc' ? 'desc' : 'asc' );
        else
            this.sortedDirection = 'asc';

        let isReverse = this.sortedDirection === 'asc' ? 1 : -1;

        if ( colName )
            this.sortedColumn = colName;
        else
            colName = this.sortedColumn;

        switch ( colName ) {

            case "Name":
            if ( this.sortedDirection == 'asc' )
                this.nameUpBool = true;
            else
                this.nameDWBool = true;
            
            break;

            case "AccountNumber":
            if ( this.sortedDirection == 'asc' )
                this.noUpBool = true;
            else
                this.noDWBool = true;
            
            break;

            case "Industry":
            if ( this.sortedDirection == 'asc' )
                this.indUpBool = true;
            else
                this.indDWBool = true;
            
            break;

            case "Rating":
            if ( this.sortedDirection == 'asc' )
                this.rateUpBool = true;
            else
                this.rateDWBool = true;
            
            break;

            case "Type":
            if ( this.sortedDirection == 'asc' )
                this.typeUpBool = true;
            else
                this.typeDWBool = true;
            
            break;

            case "Phone":
            if ( this.sortedDirection == 'asc' )
                this.phoneUpBool = true;
            else
                this.phoneDWBool = true;
            
            break;

        }

        this.records = JSON.parse( JSON.stringify( this.records ) ).sort( ( a, b ) => {
            a = a[ colName ] ? a[ colName ].toLowerCase() : 'z'; 
            b = b[ colName ] ? b[ colName ].toLowerCase() : 'z';
            return a > b ? 1 * isReverse : -1 * isReverse;
        });

    }

}

Apex Class:
public with sharing class AccountController { 
 
    @AuraEnabled( cacheable = true ) 
    public static List< Account > fetchAccounts() { 
     
        return [ SELECT Id, Name, Industry, AccountNumber, Rating, Type, Phone 
                   FROM Account 
                  LIMIT 10 ]; 
         
    } 
     
}

Output:



How to setTimeout before calling subTab() in Salesforce workspaceAPI?

Sample Code:

Aura Component:

<aura:component implements="flexipage:availableForAllPageTypes" access="global" >
   
    <lightning:workspaceAPI aura:id="workspace" />
    <lightning:utilityBarAPI aura:id="utilitybar"/>
    <lightning:button label="Open Tab with Subtab" onclick="{! c.openTabWithSubtab }" />
   
</aura:component>

JavaScript Controller:

({
   
    openTabWithSubtab : function(component, event, helper) {
       
        var workspaceAPI = component.find("workspace");
        workspaceAPI.openTab({
            recordId: '0015w0000298JM7AAM',
            focus: true
        }).then(function(response) {
            console.log( ' Parent Response is ' + response );
            setTimeout($A.getCallback(function() {
                workspaceAPI.openSubtab({
                    parentTabId: response,
                    recordId: '0035w000034EYn1AAG',
                    focus: true
                }).then(function(response) {
                    console.log( 'Child Response is ' + response );
                });
            }), 1000);
        })
        .catch(function(error) {
            console.log( 'Error is ' + error );
        });
       
    }
   
})

How to find/filter AsyncApexJob using Submitted By and Submitted Date in Salesforce?

Sample SOQL:

SELECT COUNT(Id) FROM AsyncApexJob WHERE JobType = 'Future' AND CreatedById = '<UserId>' AND CreatedDate = TODAY

SELECT COUNT(Id) FROM AsyncApexJob WHERE JobType = 'Future' AND CreatedById = '<UserId>' AND CreatedDate = YESTERDAY

December 30, 2020

Adding query parameters or URL Parameters using lightning navigation in LWC

Use state attribute to pass query parameters or URL parameters in lightning navigation.
 
Sample Code:
 
Publishing Component:

Apex Class:
public with sharing class AccountController {
 
    @AuraEnabled( cacheable = true )
    public static List< Account > fetchAccounts() {
        
        return [ SELECT Id, Name, Industry FROM Account LIMIT 10 ];
         
    }
     
}


HTML:
<template>
     
    <lightning-card title = "Accounts" icon-name = "custom:custom63">
 
        <div class = "slds-m-around_medium">
 
            <template if:true = {accounts}>
                 
                <div style="height: 300px;">
 
                    <lightning-datatable key-field="Id"
                                         data={accounts}
                                         columns={columns}
                                         hide-checkbox-column="true"
                                         show-row-number-column="true"
                                         onrowaction={handleRowAction}>
                    </lightning-datatable>
 
                </div>                  
     
            </template>
     
            <template if:true = {error}>
 
                {error}>
                 
            </template>
 
        </div>
 
    </lightning-card>
 
</template>


JavaScript:
import { LightningElement, track, wire } from 'lwc';
import fetchAccounts from '@salesforce/apex/AccountController.fetchAccounts';
import { NavigationMixin } from 'lightning/navigation';

const actions = [
    { label: 'View', name: 'view' },
    { label: 'Edit', name: 'edit' },
];
 
const columns = [   
    { label: 'Name', fieldName: 'Name' },
    { label: 'Industry', fieldName: 'Industry' },
    {
        type: 'action',
        typeAttributes: { rowActions: actions },
    },
];

export default class LightningDataTableLWC extends NavigationMixin( LightningElement ) {
     
    @track accounts;
    @track error;
    @track columns = columns;
 
    @wire(fetchAccounts)
    accountData( { error, data } ) {
        
        if ( data ) {

            this.accounts = data;
            this.error = undefined;

        } else if ( error ) {
           
            if ( Array.isArray( error.body ) )
                console.log( 'Error is ' + error.body.map( e => e.message ).join( ', ' ) );
            else if ( typeof error.body.message === 'string' )
                console.log( 'Error is ' + error.body.message );

        }

    }

    handleRowAction( event ) {

        const actionName = event.detail.action.name;
        const row = event.detail.row;
        switch ( actionName ) {
            case 'view':
                this[NavigationMixin.Navigate]({
                    type: 'standard__recordPage',
                    attributes: {
                        recordId: row.Id,
                        actionName: 'view'
                    },
                    state: {
                        c__sample: 'testing'
                    }

                });
                break;
            case 'edit':
                this[NavigationMixin.Navigate]({
                    type: 'standard__recordPage',
                    attributes: {
                        recordId: row.Id,
                        objectApiName: 'Account',
                        actionName: 'edit'
                    }
                });
                break;
            default:
        }

    }

}


meta.xml:
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>49.0</apiVersion>
    <isExposed>true</isExposed>
    <targets>
        <target>lightning__Tab</target>
    </targets>
</LightningComponentBundle>

Subscribing Component:

HTML:
<template>
    <lightning-card>
        Record Id is {recordId}
        <br/>
        Sample value is {strSample}
    </lightning-card>
</template>


JavaScript:
import { LightningElement, wire, api } from 'lwc';
import { CurrentPageReference } from 'lightning/navigation';

export default class SampleAccountLWC extends LightningElement {

    strSample;
    @api recordId;

    @wire(CurrentPageReference)
    currentPageReference;

    connectedCallback() {
       
        console.log( 'Param ' + this.currentPageReference.state.c__sample );
        this.strSample = this.currentPageReference.state.c__sample;

   
    }

}


meta.xml:
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>50.0</apiVersion>
    <isExposed>true</isExposed>
    <targets>
        <target>lightning__RecordPage</target>
    </targets>
</LightningComponentBundle>


Output:
 


Experienced Page Time/EPT Salesforce Lightning Experience


Experienced Page Time is to add an EPT counter directly to Lightning Experience, which displays in the header. EPT is the time it takes to download and display the entire content of a webpage in a browser window.

1. Add ?eptVisible=1 to the end of the URL. To turn off after testing, use ?eptVisible=0.
2. Enable Lightning Component Debug Mode from Setup.





Note:
System exception 'ConcurrentUiRequests Limit exceeded' will be raised when you exceed governor limitations for your Salesforce organization. By default this is typically set to 25 long running UI requests for 10 seconds. This may vary depending on your Salesforce edition (displayed in the title bar of your browser).

December 29, 2020

Re-Usable Custom Table with nested iterator using LWC in Salesforce

Sample Code:

Apex Class:

public with sharing class CustomTableController {
    
    @AuraEnabled( cacheable = true )
    public static List < sObject > fetchRecords( String strRecordId, String strField, String strObjectName, String strColumns ) {
     
        String strSOQL = ' SELECT Id, ' + strColumns + ' FROM ' + strObjectName + ' WHERE ' + strField;
        strSOQL += ' = \'' + strRecordId + '\'';
        system.debug( 'SOQL is ' + strSOQL );
        return Database.query( strSOQL );
         
    }

}

customTableColumn.html:
<template>
    {strValue}
</template>

customTableColumn.js:
import { LightningElement, api } from 'lwc';

export default class CustomTableColumn extends LightningElement {

    @api column;
    @api record;
    strValue

    connectedCallback() {

        this.strValue = this.record[ this.column ];

    }
    
}

customTableColumn.js-meta.xml:
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>50.0</apiVersion>
    <isExposed>false</isExposed>
</LightningComponentBundle>

customTable.html:
<template>
    <lightning-card>
        <table class="slds-table slds-table_cell-buffer slds-table_bordered slds-table_col-bordered">
            <thead>
                <tr>
                    <template for:each={labelsArr} for:item="col">
                        <th key={col}>{col}</th>
                    </template>
                </tr>
            </thead>
            <tbody>
                <template for:each={listRecs} for:item="rec">
                    <tr key={rec.Id}>
                        <template for:each={colsArr} for:item="col">
                            <td key={col}><c-custom-table-column column={col} record={rec}></c-custom-table-column></td>
                        </template>
                    </tr>
                </template>
            </tbody>
        </table>
    </lightning-card>
</template>

customTable.js:
import { LightningElement, api, wire } from 'lwc';
import fetchRecs from '@salesforce/apex/CustomTableController.fetchRecords';

export default class CustomTable extends LightningElement {

    @api recordId;
    @api columns;
    @api field;
    @api objName;
    @api labels;
    colsArr;
    labelsArr;
    listRecs;

    connectedCallback() {
    
        this.colsArr = this.columns.split( "," );
        this.labelsArr = this.labels.split( "," );
        console.log( "Labels are " + JSON.stringify( this.labelsArr ) );

    }

    @wire( fetchRecs, { strRecordId: '$recordId', strField: '$field', strObjectName: '$objName', strColumns: '$columns' } )  
    wiredRec( { error, data } ) {

        if ( data ) {

            console.log( 'Records are ' + JSON.stringify( data ) );
            this.listRecs = data;
            console.log( 'Records are ' + JSON.stringify( this.listRecs ) );

        } else if ( error ) {

            this.listRecs = null;
            this.error = error;

        }
        
    }

}

customTable.js-meta.xml:
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>50.0</apiVersion>
    <isExposed>true</isExposed>
    <targets>
        <target>lightning__RecordPage</target>
    </targets>
    <targetConfigs>
        <targetConfig targets="lightning__RecordPage">
            <property name="columns" label="Columns" type="String" />
            <property name="field" label="Field" type="String" />
            <property name="objName" label="Object Name" type="String" />
            <property name="labels" label="Labels" type="String" />
        </targetConfig>
    </targetConfigs>
</LightningComponentBundle>

Output:




How to use Session Id in ANT tool in Salesforce without username and password?

How to use Session Id in ANT tool in Salesforce without username and password?    

build.xml:        
    <target name="deploy">
        <sf:deploy
        sessionId="<SessionId>"
        serverurl="${sf.serverurl}"
        testLevel="RunLocalTests"
        deployroot="Retrieve"/>
    </target>

Callout Exception Messages in Salesforce

Sample Code:

try {
   
    HTTP h = new HTTP();
    HTTPRequest req = new HTTPRequest();
    req.setEndPoint( 'https://api.github.com/users/hadley/orgs' );
    req.setTimeOut( 1 );
    req.setMethod( 'GET');
    HTTPResponse res = h.send( req ); 
   
}
catch ( System.CalloutException ex ) {
   
    System.debug( 'Error Message is ' + ex.getmessage() );
    system.debug( 'Line Number is ' + ex.getLineNumber() );
    system.debug( 'Stace Trace String is ' + ex.getStackTraceString() );
   
}


Output:


How to monitor/view tabs/workitems opened by Agents via Omni-Channel Supervisor Tab in Salesforce?

1. Enable Conversation monitoring in Supervisor Settings.


2. In Supervisor Tab, expand an agent to Monitor/View the Chats.

3. To view the Conversation, click Monitor link.



Note:
Even though the Agent ended the chat, the capacity is not released. Capacity will be released once the Agent closes the Tab.

Date and Datetime formatting in Salesforce Lightning Web Component

Sample Code:

HTML:

<template>
    <div class="slds-box slds-theme--default">
        <table class="slds-table slds-table_cell-buffer slds-table_bordered slds-table_striped">
            <thead>
                <tr class="slds-line-height_reset">
                    <th class="" scope="col">
                        Account Name
                    </th>
                    <th class="" scope="col">
                        Created Date
                    </th>
                    <th class="" scope="col">
                        Effective Date
                    </th>
                </tr>
            </thead>
            <tbody>
                <template iterator:it={records}>
                    <tr class="slds-hint-parent" key = {it.value.Id}>
                        <td data-label="Account Name">
                            <div class="slds-cell-wrap">{it.value.Name}</div>
                        </td>
                        <td data-label="Account Number">
                            {it.value.CreatedDate}
                        </td>
                        <td data-label="Owner">
                            <div class="slds-cell-wrap">{it.value.Effective_Date__c}</div>
                        </td>
                    </tr>
                </template>
            </tbody>
        </table>
    </div>
</template>

JavaScript:
import { LightningElement, wire } from 'lwc';
import fetchAccounts from '@salesforce/apex/AccountController.fetchAccounts';
//import LOCALE from '@salesforce/i18n/locale';

export default class Sample extends LightningElement {

    records;
    error;

    @wire( fetchAccounts )  
    wiredAccount( { error, data } ) {
        if ( data ) {

            let rows = JSON.parse( JSON.stringify( data ) );
            console.log( 'Rows are ' + JSON.stringify( rows ) );
            const options = {
                year: 'numeric', month: 'numeric', day: 'numeric',
                hour: 'numeric', minute: 'numeric', second: 'numeric',
                hour12: false
              };
                
            for ( let i = 0; i < rows.length; i++ ) {  

                let dataParse = rows[ i ];

                if ( dataParse.Effective_Date__c ) {
                    
                    let dt = new Date( dataParse.Effective_Date__c );
                    dataParse.Effective_Date__c = new Intl.DateTimeFormat( 'en-US' ).format( dt );
                
                }

                if ( dataParse.CreatedDate ) {
                    
                    let dt = new Date( dataParse.CreatedDate );
                    dataParse.CreatedDate = new Intl.DateTimeFormat( 'en-US', options ).format( dt );
                
                }

            }
                
            this.records = rows;
            this.error = undefined;

        } else if ( error ) {

            this.error = error;
            this.records = undefined;

        }
    }  

}

Apex Class:
public with sharing class AccountController {
 
    @AuraEnabled( cacheable = true )
    public static List< Account > fetchAccounts() {
     
        return [ SELECT Id, Name, CreatedDate, Effective_Date__c FROM Account LIMIT 10 ];
         
    }
     
}

Output:



What Is DMARC?

Domain-based Message Authentication, Reporting, and Conformance (DMARC) is an email authentication, policy, and reporting protocol. It’s built on top of Sender Policy Framework (SPF) and DomainKeys Identified Mail (DKIM) protocols. If neither of those authentication methods passes, the DMARC policy determines what to do with the message. Salesforce supports and recommends DMARC. It’s up to you to determine whether you implement it for your domain.

DMARC is a second layer of authentication after DKIM and SPF. If an email doesn't pass DKIM and SPF authentication, DMARC policy tells the receiver what to do with the message. For example, it can reject some email messages and quarantine others.

Reference Link - https://help.salesforce.com/articleView?id=emailadmin_dmarc.htm&type=5

Fixed Header in Custom Table using LWC in Salesforce

Sample Code:

Apex Class:

public with sharing class AccountController {
 
    @AuraEnabled( cacheable = true )
    public static List< Account > fetchAccounts() {
     
        return [ SELECT Id, Name, Industry, AccountNumber, Rating, Type, Phone
                   FROM Account
                  LIMIT 100 ];
         
    }
     
}

HTML:
<template>
    <div class="slds-box slds-theme--default">
        <div>
            <div class="tableFixHead">
                <table class="slds-table slds-table_cell-buffer slds-table_bordered slds-table_striped">
                    <thead>
                        <tr>
                            <th scope="col">
                                Account Name
                            </th>
                            <th scope="col">
                                Account Number
                            </th>
                            <th scope="col">
                                Industry
                            </th>
                            <th scope="col">
                                Rating
                            </th>
                            <th scope="col">
                                Type
                            </th>
                            <th scope="col">
                                Phone
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        <template iterator:it={records}>
                            <tr key={it.value.Id}>
                                <td data-label="Account Name">
                                    <div class="slds-cell-wrap">{it.value.Name}</div>
                                </td>
                                <td data-label="Account Number">
                                    <div class="slds-cell-wrap">{it.value.AccountNumber}</div>
                                </td>
                                <td data-label="Industry">
                                    <div class="slds-cell-wrap">{it.value.Industry}</div>
                                </td>
                                <td data-label="Rating">
                                    <div class="slds-cell-wrap">{it.value.Rating}</div>
                                </td>
                                <td data-label="Type">
                                    <div class="slds-cell-wrap">{it.value.Type}</div>
                                </td>
                                <td data-label="Phone">
                                    <div class="slds-cell-wrap">{it.value.Phone}</div>
                                </td>
                            </tr>
                        </template>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</template>

JavaScript:
import { LightningElement, wire } from 'lwc';
import fetchAccounts from '@salesforce/apex/AccountController.fetchAccounts';

export default class Sample extends LightningElement {

    records;
    error;

    @wire( fetchAccounts )  
    wiredAccount( { error, data } ) {

        if (data) {

            this.records = data;
            this.error = undefined;

        } else if ( error ) {

            this.error = error;
            this.records = undefined;

        }

    }  

}

CSS:
.tableFixHead {
    overflow: auto;
    height: 250px;
}

.tableFixHead table {
    border-collapse: collapse;
    width: 100%;
}

.tableFixHead th {
    position: sticky;
    top: 0;
    z-index: 4;
    background: white;
 }

Output:



This Contact doesn't have any associated Messaging Users. Ensure that any Messaging Users have their Contact field set up properly and that they haven't opted out of Messaging

1. Make sure the user is added the Queue of the Messaging Channel.

 


Send Email to Members in Salesforce Queue

If you want to send an email notification to all queue members individually when a new case gets added to the queue.


The Send Email to queue members alert will only work if you are using Case Assignment Rules and Active Assignment checkbox to move Case to a Queue. If you are moving the case Manually to a Queue or using a Workflow, it does not trigger the Email alert.

Reference Link - https://help.salesforce.com/articleView?id=000323036&type=1&mode=1

DateTime.valueOf() returning next year date for December month dates

In valueOf(), the specified string should use the standard date format “yyyy-MM-dd HH:mm:ss”.

Formatting using YYYY(Uppercase) is NOT the same as yyyy(Lowercase). So, change YYYY(Uppercase) to yyyy(Lowercase) to fix this issue.

Reference Link - https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_datetime.htm
 
Sample Code:
String customDateFieldValue = '2020-03-12 20:03:20';
System.debug( DateTime.valueOf( customDateFieldValue ).format( 'yyyy-MM-dd' ) );
customDateFieldValue = '2020-12-29 20:03:20';
System.debug( DateTime.valueOf( customDateFieldValue ).format( 'YYYY-MM-dd' ) );


Output:

 

December 28, 2020

Re-use CSS in LWC using CSS Module

cssLibrary.css:
h1 {
    text-align: center;
    font-weight: bold;
    font-size: large;
    color: black;
}

.bgCSS {
    background: black;
    color: white;
    font-weight: bold;
}


cssLibrary.js-meta.xml:
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>49.0</apiVersion>
    <isExposed>false</isExposed>
</LightningComponentBundle>

 
sample.html:
<template>
    <div class="slds-box slds-theme--default">
        <h1>
            Testing in Sample
        </h1>
        <div class="bgCSS">
            Testing Sample
        </div>
    </div>
</template>

sample.js:
import { LightningElement } from 'lwc';

export default class Sample extends LightningElement {}


sample.css:
@import 'c/cssLibrary';

sample.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__Tab</target>
    </targets>
</LightningComponentBundle>
 
Output:



How to pass data from one LWC to another in Salesforce?

Sample Code:

sample.messageChannel-meta.xml:
<?xml version="1.0" encoding="UTF-8"?>
<LightningMessageChannel xmlns="http://soap.sforce.com/2006/04/metadata">
    <masterLabel>Sample</masterLabel>
    <isExposed>true</isExposed>
    <description>This is a sample Lightning Message Channel.</description>
    <lightningMessageFields>
        <fieldName>variable1</fieldName>
        <description>Variable 1</description>
    </lightningMessageFields>
</LightningMessageChannel>

component1.html:
<template>
    <lightning-card title="Component 1">
        <lightning-button label="Publish" onclick={handleClick}></lightning-button>
    </lightning-card>
</template>

component1.js:
import { LightningElement, wire } from 'lwc';
import SAMPLEMC from "@salesforce/messageChannel/Sample__c";
import { publish, MessageContext } from 'lightning/messageService';

export default class Component1 extends LightningElement {

    @wire(MessageContext)
    messageContext;

    handleClick() {

        const message = {
            variable1: "Test"
        };
        publish( this.messageContext, SAMPLEMC, message );

    }

}

component1.js-meta.xml:
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>50.0</apiVersion>
    <isExposed>true</isExposed>
    <targets>
        <target>lightning__AppPage</target>
    </targets>
</LightningComponentBundle>

component2.html:
<template>
    <lightning-card title="Component 2">
        Message Received is {receivedMessage}
    </lightning-card>
</template>

component2.js:
import { LightningElement, wire } from 'lwc';
import SAMPLEMC from "@salesforce/messageChannel/Sample__c";
import { subscribe, MessageContext, APPLICATION_SCOPE } from 'lightning/messageService';

export default class Component2 extends LightningElement {

    receivedMessage;
    subscription = null;

    @wire(MessageContext)
    messageContext;

    connectedCallback() {

        if ( this.subscription ) {
            return;
        }
        this.subscription = subscribe(
            this.messageContext,
            SAMPLEMC, ( message ) => {
                this.handleMessage( message );
            },
            {scope: APPLICATION_SCOPE}
        );

    }

    handleMessage( message ) {

        console.log( 'Message received is ' + JSON.stringify( message ) );
        this.receivedMessage = message ? JSON.stringify( message, null, '\t' ) : 'No Message Payload';

    }

}

component2.js-meta.xml:
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>50.0</apiVersion>
    <isExposed>true</isExposed>
    <targets>
        <target>lightning__AppPage</target>
    </targets>
</LightningComponentBundle>

Output:


For code in GitHub, check the below link