Knowledge Tab missing in Salesforce Lightning


1. Go to Knowledge Settings in Setup.

2. Make sure "Enable Lightning Knowledge" check box is checked.

We couldn't display the conversation entries exception in Salesforce


To Access ConversationEntry entity, "Access Conversation Entries" profile Permission is mandatory.

Re-Usable lightning record update form using Lightning Web Component LWC in Salesforce

Sample Code:
HTML:
<template>
    <lightning-card>
        <lightning-record-form
            record-id={recordId}
            object-api-name={objectApiName}
            fields={fieldsList}
            mode="edit"
            onsubmit={handleSubmit}
            onsuccess={handleSuccess}>
        </lightning-record-form>
    </lightning-card>
</template>

JavaScript:
import { api, LightningElement } from 'lwc';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';

export default class ReusableRecordUpdateForm extends LightningElement {

    @api recordId;
    @api objectApiName;
    @api fields;
    fieldsList;

    connectedCallback() {

        console.log( 'Record Id is ' + this.recordId );
        console.log( 'fields is ' + this.fields );
        this.fieldsList = this.fields.split( ';' );
        console.log( 'fieldsList is ' + JSON.stringify( this.fieldsList ) );

    }

    handleSubmit( event ) {

        event.preventDefault();
        const fields = event.detail.fields;
        console.log( 'Values are ' + JSON.stringify( fields ) );
        this.template.querySelector( 'lightning-record-form' ).submit( fields );

     }

    handleSuccess( event ) {

        const evt = new ShowToastEvent( {
            title: "Record Updated",
            message: "Record Updated Successfully!!!",
            variant: "success"
        } );
        this.dispatchEvent( evt );

    }

}

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__RecordPage</target>
    </targets>
    <targetConfigs>
        <targetConfig targets="lightning__RecordPage">
            <property name="fields" type="String" label="Fields" description="Enter the fields separated by semicolon" required="true"/>
        </targetConfig>
    </targetConfigs>
</LightningComponentBundle>


Configuration and Output: 
 
Contact Page Configuration:
 

Account Page Configuration:
 

Contact Page Output:
 
 
Account Page Output:

How to reset lightning-record-edit-form and get also get record id in Salesforce?

Sample Code:
HTML:
<template>
    <lightning-card title="Lead Creation">
        <lightning-record-edit-form object-api-name="Lead" onsubmit={handleSubmit} onsuccess={handleSuccess}>
            <lightning-messages></lightning-messages>
            <lightning-input-field field-name="FirstName"></lightning-input-field>
            <lightning-input-field field-name="LastName"></lightning-input-field>
            <lightning-input-field field-name="Email"></lightning-input-field>
            <lightning-input-field field-name="Phone"></lightning-input-field>
            <lightning-input-field field-name="Company"></lightning-input-field>
            <lightning-button label="Create Lead" variant="brand" type="submit"></lightning-button>&nbsp;&nbsp;&nbsp;  
            <lightning-button label="Reset" variant="brand" onclick={handleReset}></lightning-button>     
        </lightning-record-edit-form>
    </lightning-card>
</template>

JavaScript:
import { LightningElement } from 'lwc';
import {ShowToastEvent} from 'lightning/platformShowToastEvent';

export default class LeadCreationTab extends LightningElement {

    handleSubmit( event ) {

        event.preventDefault();        
        let fields = event.detail.fields;
        console.log( 'Fields are ' + JSON.stringify( fields ) );
        this.template.querySelector( 'lightning-record-edit-form' ).submit( fields );

    }

    handleReset( event ) {

        const inputFields = this.template.querySelectorAll( 'lightning-input-field' );
        if ( inputFields ) {
            inputFields.forEach( field => {
                field.reset();
            } );
        }

    }

    handleSuccess( event ) {
        
        console.log( 'Record Id is ' + event.detail.id );
        this.dispatchEvent(
            new ShowToastEvent( {
                title: 'Lead Submission Result',
                message: 'Lead Submitted Successfully',
                variant: 'success',
                mode: 'sticky'
            } )
        );

    }

}

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 show a panel only after selection of value from another panel in Splunk?

Use Drilldown Editor:



Sample XML:
<form>
  <label>Sample Explore</label>
  <search id="Event_transcript_search">
    <query>PLEASE ENTER YOUR QUERY</query>
    <earliestTime>$earliest$</earliestTime>
    <latestTime>$latest$</latestTime>
  </search>
  <search id="Event_key_search">
    <query>
      PLEASE ENTER YOUR QUERY
    </query>
    <earliestTime>$earliest$</earliestTime>
    <latestTime>$latest$</latestTime>
  </search>
  <fieldset submitButton="true" autoRun="false">
    <input type="text" token="OrgId">
      <label>Org Id</label>
      <default></default>
    </input>
    <input type="text" token="sampleToken">
      <label>Sample</label>
      <default></default>
    </input>
    <input type="time">
      <label>Time Frame</label>
      <default>
        <earliest>-15m</earliest>
        <latest>now</latest>
      </default>
    </input>
  </fieldset>
  <row>
    <panel>
      <table>
        <title>Event Keys</title>
        <search base="Event_transcript_search">
          <query>PLEASE ENTER YOUR ADDITIONAL STATEMENTS IN THE QUERY</query>
          <earliest>[email protected]</earliest>
          <latest>now</latest>
        </search>
        <option name="drilldown">cell</option>
        <drilldown>
          <set token="EventKey">$click.value2$</set>
        </drilldown>

      </table>
    </panel>
  </row>
  <row>
    <panel depends="$EventKey$">
      <table>
        <title>Events - $EventKey$</title>
        <search base="Event_key_search">
          <query>PLEASE ENTER YOUR ADDITIONAL STATEMENTS IN THE QUERY</query>
          <earliest>[email protected]</earliest>
          <latest>now</latest>
        </search>
        <option name="drilldown">row</option>
      </table>
    </panel>
  </row>
</form>

In the above example, when a cell is clicked from that panel, it captures the value and stores it in EventKey toekn. Then, the next panel is displayed only after that. In the initial dashboard load, the panel won't be loaded as it depends on EventKey token.

Chat not loading when navigating in Salesforce Experience Cloud/Community Cloud

To ensure that chat sessions are continued across pages, place the Embedded Service component in your site's template footer. 
 
 

Iterate Multi Picklist in Flow without Apex in Salesforce

Sample Flow:
 
 
Variables:
listSelectedIndustries is a Collection Variable to hold list of selected industries to show it on the Selected Industries Screen.

currentVal is to get the first value from the selected multi picklist values.

updatedIndustriesSelection is to hold the remaining values from the selected multi picklist values after removing the first value.

AccountIndustryPicklistValues is Picklist Choice Set to get picklist values from Industry field.

listSelectedIndustriesInitially is used to hold the selected values from the Home Screen. As we iterate, the values will be removed one by one in Semi Colon Assignment.

Home Screen:
To select multi picklist values.

 
Initial Industries Assignment:
Assigns listSelectedIndustriesInitially variable with the selection from the Home Screen.


Iterate Industries Selection:
Contains Semi Colon Node:

Checks whether listSelectedIndustriesInitially contains semi colon ';'.

Doesn't Contains Semi Colon Node:
Default. listSelectedIndustriesInitially doesn't contains semi colon ';'.
 

Semi Colon Assignment:
Adds currentVal formula variable value to the listSelectedIndustries collection variable.
Assigns listSelectedIndustriesInitially with the updateIndustriesSelection formula variable value.
 

No Semi Colon Assignment:
Adds updateIndustriesSelection formula variable value to the listSelectedIndustries collection variable.
 
 
Selected Industries Screen:
Displays the listSelectedIndustries collection variable.

 
Output:
 
 

Polymorphic Field in SOQL Queries in Salesforce

For Task Object with What field:
Apex:

List < Task > listTasks =
[ SELECT Id, Subject,  
    TYPEOF What
    WHEN Opportunity THEN Name, Amount
    END
FROM Task
LIMIT 15 ];

for ( Task objTask : listTasks ) {

    System.debug( objTask.Subject );

    if ( objTask.What instanceof Opportunity ) {
    
        Opportunity objOpportunity = objTask.What;
        System.debug( objOpportunity.Name );
        System.debug( objOpportunity.Amount );
       
    }
    
}

SOQL:
SELECT WhatId FROM Task WHERE What.Type = 'Opportunity'

For Conversation Entry Object with Conversation field:
Apex:
List < ConversationEntry > listCEs =
[ SELECT Id, ActorName, ActorType, EntryType, Message,  
    TYPEOF Conversation
    WHEN MessagingSession THEN MessagingChannel.DeveloperName, PreviewDetails
    ELSE Name
    END
FROM ConversationEntry
LIMIT 15 ];

for ( ConversationEntry objCE : listCEs ) {

    if ( objCE.Conversation instanceof MessagingSession ) {
    
        MessagingSession objMS = objCE.Conversation;
        System.debug( objMS.MessagingChannel.DeveloperName );
        System.debug( objMS.PreviewDetails );
       
    }
    
}

SOQL:
SELECT MessagingChannel.DeveloperName, PreviewDetails
FROM MessagingSession
WHERE Id IN (
    SELECT ConversationId FROM ConversationEntry WHERE CreatedDate = LAST_N_DAYS:15
)


Reference Article:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_SOQL_polymorphic_relationships.htm

How to pass list of string from Flow to LWC in Salesforce?

1. Lightning Web Component is
HTML:
<template>
    Selected industries are
    <template for:each={Industries} for:item="ind">
        <p key={ind}>{ind}</p>
    </template>
</template>

JavaScript:
import { LightningElement, api } from 'lwc';

export default class TestFlowComponent extends LightningElement {

    @api Industries;

}

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__FlowScreen</target>
    </targets>
    <targetConfigs>
        <targetConfig targets="lightning__FlowScreen">
            <property name="Industries" label="Industries" type="String[]" />
        </targetConfig>
    </targetConfigs>
</LightningComponentBundle>


2. Create the following Apex Class to parse Multipicklist selection to list of String.
 
public class MultipicklistParser {
    
    @InvocableMethod
    public static List < List < String > > parseMultipicklist( List < String > strInputs ) {
        
        if ( strInputs.size() > 0 ) {
            
            List < List < String > > selectedOptions = new List < List < String > >();
            List < String > listTemp = strInputs.get( 0 ).split( ';' );
            selectedOptions.add( listTemp );
            return selectedOptions;
            
        }
        
        return null;
        
    }
    
}

 
3. Create a Flow.


Flow Resources:
 

 Account Industry Picklist Choice Set:
 

 

 


Output:
 
 

How to show a to-do list on the case page in each stage in Salesforce?

1. Update the Case Status Field as needed.


2. Create a Support Process.


3. Create a Record Type.


4. Enable Path Settings and add the fields and Guidance for Success.
 
Output:
 
New Case Status:
 

 Assigned Case Status:
 

 Working Case Status:
 

 Closed Case Status:
 

GACKs in Salesforce

"An internal server error has occurred." is nothing but a GACK. Check the following article for more information:

Vote for the following idea for making GACKs public reference:

How to subscribe to Platform Event using Lightning Web Component in Salesforce?

HTML:
<template>
    <lightning-card title="EmpApi Example" icon-name="custom:custom14">
        <div class="slds-m-around_medium">
            <lightning-button variant="success" label="Subscribe" title="Subscribe"
                onclick={handleSubscribe} disabled={isSubscribeDisabled}
                class="slds-m-left_x-small"></lightning-button>
            <lightning-button variant="destructive" label="Unsubscribe" title="Unsubscribe"
                onclick={handleUnsubscribe} disabled={isUnsubscribeDisabled}
                class="slds-m-left_x-small"></lightning-button>
        </div>
        <lightning-datatable 
            key-field="ReplayId"
            data={listEvents}
            columns={columns}
            hide-checkbox-column="true">
        </lightning-datatable>  
    </lightning-card>
</template>

JavaScript:
import { LightningElement } from 'lwc';
import { subscribe, unsubscribe, onError } from 'lightning/empApi';

export default class SamplePlatformEventsListener extends LightningElement {

    channelName = '/event/Test__e';
    isSubscribeDisabled = false;
    isUnsubscribeDisabled = !this.isSubscribeDisabled;
    subscription = {};
    listEvents;
    columns = [   
        { label: 'Serial No', fieldName: 'SerialNo' }, 
        { label: 'Replay Id', fieldName: 'ReplayId' }, 
        { label: 'Schema', fieldName: 'Schema' }
    ];

    connectedCallback() {   

        this.registerErrorListener();      

    }

    handleSubscribe() {
        
        const messageCallback = ( response ) => {
            console.log( 'New message received: ', JSON.stringify( response ) );
            let val =  { 
                'SerialNo' : response.data.payload.Serial_No__c, 
                'Schema' : response.data.schema, 
                'ReplayId' : response.data.event.replayId
            };
            console.log( 'Val is ' + JSON.stringify( val ) );
            console.log( 'Events before assignment are ' + JSON.stringify( this.listEvents ) );
            
            if ( this.listEvents ) {
                this.listEvents = [ ...this.listEvents,  val ];
            } else {
                this.listEvents = [ val ];
            }

            console.log( 'Events after assignment are ' + JSON.stringify( this.listEvents ) );
        };

        subscribe( this.channelName, -1, messageCallback ).then( response => {
            console.log( 'Subscription request sent to: ', JSON.stringify( response.channel ) );
            this.subscription = response;
            this.toggleSubscribeButton( true );
        });

    }

    handleUnsubscribe() {

        this.toggleSubscribeButton( false );

        unsubscribe( this.subscription, response => {
            console.log( 'unsubscribe() response: ', JSON.stringify( response ) );
        });

    }

    toggleSubscribeButton( enableSubscribe ) {

        this.isSubscribeDisabled = enableSubscribe;
        this.isUnsubscribeDisabled = !enableSubscribe;

    }

    registerErrorListener() {

        onError( error => {
            console.log( 'Received error from server: ', JSON.stringify( error ) );
        });

    }

}

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:


"Unexpected close tag" Exception in Splunk Dashboard

This error is due to usage of < or > symbols. Do not use < or > symbols. Use &lt; and &gt; instead.

Example:
rex field=_raw "errorCode: (?<error_code>\d+)"

The above usage in the query will throw an error due to usage of < and > symbols. See the following resolution to resolve this issue.
rex field=_raw "errorCode: (?&lt;error_code&gt;\d+)"

How to display Tasks and Events from Contacts in Account Activity Timeline in Salesforce?

Use Roll up activities to a contact's primary account feature.
Note:
When an activity is associated to a contact, also display the activity under the primary account for the contact. We recommend that you don't select this option if you allow users to relate contacts to multiple accounts.

1. Go to Activity Settings.


2. Enable "Use Roll up activities to a contact's primary account".
 

Output:
 
 

How to listen to Salesforce Platform Event from simple CometD application using Java programming?

1. Install Java Development Kit 8 or later.

2. Download and Install Apache Maven.
https://maven.apache.org/index.html

3. Download and Install Eclipse.

4. Use the following command to clone the sample CometD connector.
git clone https://github.com/forcedotcom/EMP-Connector


5. Import the project using Eclipse.

6. Create a simple Platform Event.

7. In the /src/main/java/com/salesforce/emp/connector/example folder, Right-click the LoginExample.java file and select Run As | Run Configurations.
 

8. On the Arguments tab, add values for the following arguments, separated by a space.
Example:

username password /event/API_Name_Of_The_Event.


9. Publish an event from Salesforce to see it in the Eclipse Console.

Sample Code:
Test_Event__e objEvent = new Test_Event__e( Test__c = String.valueOf( system.now() ) );
EventBus.publish( objEvent );



How to notify the Case Owner if the Case is not worked for more than 5 days in Salesforce?

1. Create Escalation rule.
 
2. Create a rule entry with Case Closed equals to false.
 

 3. Create an Action to escalate at 120 hours i.e 5 days.



How to retrieve and deploy territory-based sharing rules using ANT tool in Salesforce?

SharingTerritoryRule should be used to retrieve Territory Sharing Rules.
 
package.xml:
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <members>*</members>
        <name>SharingTerritoryRule</name>
    </types>
    <version>52.0</version>
</Package>

Chatter compact is looking different in other objects Lightning Record Pages when compared to Case, Lead and Social Post object in Salesforce

The Case, Lead and Social Post objects uses the Compact Feed. Other objects doesn't use Compact Feed.
Please check the following article for reference.

Case, Lead, and Social post objects are supported to use the Compact Feed view in Lightning. 
 
Lead Chatter Component(Compact Feed):


Account Chatter Component(Non-Compact Feed):


Opportunity Chatter Component(Non-Compact Feed):


Case Chatter Component(Compact Feed):