Sneak Peek in Salesforce Chat


Sneak Peek in Salesforce chat allows agents to view what the visitors are typing before they send the message.

Follow  the below steps to set it up in Salesforce.

1. Create a "Chat Agent Configuration".

2. Enable "Sneak Peek Enabled".


Note:
Make sure to assign users or profiles to the Chat Agent Configuration.

Output:
 

Video Reference:

How to Setup Sneak Peek in Salesforce Chat

Tooltip Text in Salesforce Lightning Web Component LWC

Sample Code:
HTML:
<template>
    <lightning-card>
        <div class="slds-m-around_medium">
            Test<lightning-helptext content="Testing Help Text"></lightning-helptext><lightning-input variant="label-hidden"></lightning-input>
        </div>
    </lightning-card>    
</template>

JavaScript:
import { LightningElement } from 'lwc';

export default class SampleLWC extends LightningElement {}

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

 
Output:
 
 

Tooltip Text in Salesforce Lightning Aura Component

Sample Code:
<aura:component implements="force:appHostable" >
    <lightning:card>
        <div class="slds-m-around_medium">
            Test<lightning:helptext content="Testing Help Text"></lightning:helptext><lightning:input variant="label-hidden"></lightning:input>
        </div>
    </lightning:card>
</aura:component>
 
Output:
 

 

How to setup Named Credential in Salesforce for Microsoft?

Get the Client Id, Client Secret and Tenant Id from the Azure Portal.


Note:
Tenant Id should be used in the Auth. Provider Authorize Endpoint URL and Token Endpoint URL.

1. Create Auth. Provider.


2. Create the Named Credential with the Auth. Provider from the step 1.


How to create Child Case using Parent Case information in Salesforce?

A simple Quick Action can be used to create Child Case using Parent Case information in Salesforce.

1. Create a Quick Action.

Note:
Add the Predefined Field Values.

2. Add the Quick Action to the Case Page Layout.

3. Use it from the Chatter Feed Publisher Component.

Output:
 
 

System.LimitException: Too many callouts: 1 Exception in Salesforce Batch Apex



If you are using batch class, then make sure to implement "Database.AllowsCallouts".

Sample Code:

global class BatchClass implements Database.Batchable<sObject>, Database.AllowsCallouts

How to route Cases using Status field using Omni Flow in Salesforce?


1. Create required Queues and add users to it.




2. Create an Omni-Channel Flow.
 

3. Create a Record-Triggered Flow. Call the Omni Flow using Sub Flow component.


When the Case is created with Status "New", it will go to New Queue.

When the Case is created with Status "Escalated", it will go to Escalated Queue.

Video Reference:

Route Cases using Status field usin... x
Route Cases using Status field using Omni Flow in Salesforce

How to use of frontdoor.jsp to Log in using Session Id to Salesforce and Experience Cloud Site

Execute the following apex in Anonymous Apex Execute Window in Developer Console.

String strURL = System.URL.getSalesforceBaseUrl().toExternalForm();
strURL += '/secur/frontdoor.jsp?sid=' + UserInfo.getSessionId().SubString(15);
System.debug( 'URL: ' +strURL );


Use the URL to access Salesforce.

Replace coma with new Line using Salesforce Apex

Sample Trigger:
trigger AccountTrigger on Account ( before insert, before update ) {

    for ( Account objAcc : trigger.new ) {
    
        if ( String.isNotBlank( objAcc.Description ) ) {
    
            objAcc.Description = objAcc.Description.replace( ',', '\n' );
        
        }
                  
    }
    
}
 
Test Class for the Trigger:
@isTest
public class AccountTriggerTest {
    
    static testMethod void acctInsertTest() {
        
        Account objAcc = new Account( Name = 'Testing', Description = 'A,B' );
        insert objAcc;
        objAcc = [ SELECT Description FROM Account WHERE Id =: objAcc.Id ];
        System.assertEquals( objAcc.Description, 'A\nB' );
        
    }
    
}

Output:



Simple Flow Orchestrator in Salesforce


To build Salesforce Orchestration, check the following:

Sample Flow Orchestrator:
Scenario:
When an Account record is created.

Stage 1:
1. Update the Case Description to Stage 1.
2. Wait for the Screen Flow to complete.

Stage 2:
1. Update the Case Description to Stage 2.

To create Salesforce Flow Orchestrator, follow the below steps.

1. Go to Flows in Setup.

2. Click New button.

3. Select All + Templates tab.


Sample Flow Orchestration
 
 
Step 1 of Stage 1:

 
Step 2 of Stage 1:
 
Step 1 of Stage 2:


Add the Orchestrator Work Guide to the Lightning Record Page
 

Output:
 
When the account record is created, it will update the Description to Stage 1, sends an email for the interactive step 2 to complete and the Screen Flow will be available in the Work Guide to Complete.

 
Sample Email Notification for the Interactive Step:
 
 
Video Reference:

Salesforce Simple Flow Orchestration

How to display Account Name while displaying Contacts in Lightning Data Table in Salesforce Lightning Web Component?

Sample Code:
Apex Class:
public with sharing class ContactController {

    @AuraEnabled( cacheable=true )
    public static List < Contact > fetchContacts(){    

        return [
            SELECT Id, Name, Account.Name FROM Contact LIMIT 5
        ];

    }

}

 
Lightning Web Component:
HTML:
<template>
    <lightning-card>
        <lightning-datatable
                key-field="Id"
                data={records}
                columns={columns}
                hide-checkbox-column="true">
        </lightning-datatable>
    </lightning-card>
</template>

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

const columns = [
    { label: 'Contact Name', fieldName: 'Name' },
    { label: 'Account Name', fieldName: 'AccName' }
];

export default class DataTable extends LightningElement {

    records;
    error;
    columns = columns;
    draftValues = [];

    @wire( fetchContacts )  
    wiredAccount( value ) {

        const { data, error } = value;

        if ( data ) {
            
            let tempRecords = JSON.parse( JSON.stringify( data ) );
            tempRecords = tempRecords.map( row => {
                return { ...row, Name: row.Name, AccName: ( row.Account ? row.Account.Name : null ) };
            })
            this.records = tempRecords;
            this.error = undefined;

        } else if ( error ) {

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

        }

    }  

}

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

 
Output:
 

How to find users part of a Permission Sets in Salesforce?

SOQLs:
 
SOQL to find users part of the Permission Set:
SELECT Assignee.Name FROM PermissionSetAssignment
WHERE PermissionSetId = '0PS8c000003LCCL'
 

SOQL to find users part of the Permission Group :
SELECT Assignee.Name FROM PermissionSetAssignment
WHERE PermissionSetGroupId IN ( SELECT PermissionSetGroupId FROM PermissionSetGroupComponent WHERE PermissionSetId = '0PS8c000003LCCL' )


Test User was directly added to the Permission Set.

Test Admin user was added via Permission Set Group.

How to display First Name and Last Name instead of Nickname in Salesforce Experiece Cloud Site?



To avoid showing Nickname in the Experience Cloud Site, disable Show Nicknames in the Experience Cloud Site Administration.

1. Click Workspace from the Experience Cloud Site in All Sites in Setup.

2. Select Administration.

3. Select Preference.

4. Disable "Show nicknames".


Output:
 
 

Video Reference:

Show Full name instead of Nickname in Salesforce Experience Cloud Site

How to segregate or parse result set from Salesforce SOSL?

Sample Apex Code:

String searchQuery = 'FIND {test} IN Name FIELDS RETURNING Account( Id, Name ), Contact( Id, Name )';
List < List < sObject > > searchResult = search.query( searchQuery );
List < Account > listAccount = ( List < Account > )searchResult.get( 0 );
List < Contact > listContact = ( List < Contact > )searchResult.get( 1 );
for ( Account acc : listAccount ) {
    
    System.debug( acc );
    
}
for ( Contact con : listContact ) {
    
    System.debug( con );
    
}


How to get Access Token from Microsoft with grant_type as password using Apex in Salesforce?

Get the Tenant Id, client secret value(not the id).


Sample Code:

String strEndPoint = 'https://login.microsoftonline.com/{Enter_Tenant_Id}/oauth2/v2.0/token';
String strBody = 'grant_type=password&scope=https%3a%2f%2fgraph.microsoft.com%2f.default';
strBody += '&client_id={Enter_Client_Id}&client_secret={Enter_Client_Secret}';
strBody += '&username={Enter_Username}&password={Enter_Password}';
HttpRequest req = new HttpRequest();
req.setEndpoint( strEndPoint );
req.setMethod( 'POST' );
req.setHeader( 'Content-Length', String.valueOf( strBody.length() ) );
req.setHeader( 'Content-Type', 'application/x-www-form-urlencoded' );
req.setHeader( 'Accept', 'application/json' );
req.setBody( strBody );
req.setTimeout( 120000 );
Http http = new Http();
HTTPResponse res = http.send( req );
System.debug( res.getBody() );
JSONParser parser = JSON.createParser( res.getBody() );
String strAccessToken;

while ( parser.nextToken() != null ) {

    if ( ( parser.getCurrentToken() == JSONToken.FIELD_NAME ) && 
        ( parser.getText() == 'access_token') ) {
        
        parser.nextToken();
        strAccessToken = parser.getText();
        break;
        
    }
    
}
System.debug( 'Access Token is ' + strAccessToken ); 

How to get Access Token from Microsoft with grant_type as client_credentials using Apex in Salesforce?

Get the Tenant Id, client secret value(not the id).


Sample Code:

String strEndPoint = 'https://login.microsoftonline.com/{Enter_Tenant_Id}/oauth2/v2.0/token';
String strBody = 'grant_type=client_credentials&scope=https%3a%2f%2fgraph.microsoft.com%2f.default';
strBody += '&client_id={Enter_Client_Id}&client_secret={Enter_Client_Secret}';
HttpRequest req = new HttpRequest();
req.setEndpoint( strEndPoint );
req.setMethod( 'POST' );
req.setHeader( 'Content-Length', String.valueOf( strBody.length() ) );
req.setHeader( 'Content-Type', 'application/x-www-form-urlencoded' );
req.setHeader( 'Accept', 'application/json' );
req.setBody( strBody );
req.setTimeout( 120000 );
Http http = new Http();
HTTPResponse res = http.send( req );
System.debug( res.getBody() );
JSONParser parser = JSON.createParser( res.getBody() );
String strAccessToken;
while ( parser.nextToken() != null ) {

    if ( ( parser.getCurrentToken() == JSONToken.FIELD_NAME ) && 
        ( parser.getText() == 'access_token') ) {
        
        parser.nextToken();
        strAccessToken = parser.getText();
        break;
        
    }
}
System.debug( 'Access Token is ' + strAccessToken );

How to get Access Token for Microsoft Graph using Username and Password Flow(Delegation)?

Get the Tenant Id, client secret value(not the id).


Do POST Call to get the access token.



How to log out from Salesforce Visual Studio Code?

Use SFDX: Log Out from Default Org command. It will log out and remove the Default Org set in the project.


Use the Authorize command(">SFDX: Authorize an Org") to login again. 


Pass Custom Fields values dynamically from Amazon Contact Center flow to Voice Call Object in Salesforce

1. Custom Field in Salesforce Voice Call object.


2. Use "Set contact attributes" to pass value to the Custom Field Salesforce from the Amazon Contact Center Flow.
 
a. When 1 is pressed, Text__c will be set as A.
b. When 2 is pressed, Text__c will be set as B.
c. When the customer didn't press 1 or 2, Not Pressed will be set to Text__c field.
 
 
Get customer input configuration:
 

Output:
 
 

"Can't send messages to this recipient because they blocked you" Salesforce Messaging

Codes starting with two (2xxx) indicate a problem with the destination address.
2002 - Can't send messages to this recipient because they blocked you.
 
 
This exception is thrown since the recipient blocked the channel. Check the "Messaging Consent Status" of the Messaging End User to resolve this issue.
 
The "Messaging Consent Status" of the Messaging End User shouldn't be "Opted Out".

Pass Custom Fields values from Amazon Contact Center flow to Voice Call Object in Salesforce

1. Custom Field in Salesforce Voice Call object.


2. Use "Set contact attributes" to pass value to the Custom Field Salesforce from the Amazon Contact Center Flow.
 
 
3. Call the Set contact attributes before Invoking AWS Lambda function.


4. Test it by calling the flow. I have used it in the Inbound Call Flow. So, I made an Inbound Call to test it.

Output:
 

Reference Article: