Skip to content

Instantly share code, notes, and snippets.

View Sunil02kumar's full-sized avatar

Sunil Kumar Sunil02kumar

View GitHub Profile
@Sunil02kumar
Sunil02kumar / contactCheck.html
Created April 30, 2024 11:30
Communicate Between Unrelated LWC Components- Lightning Message Service (LMS)
<template>
<lightning-card title="Subscriber Component">
<div style="background-color:#a3ce98;border-style: solid;margin:5%;padding:2%;">
<p>This component is using LMS framework to subscribe message</p>
<div style="background-color:#7ff6f6;border-style: solid;padding:2%;">
<p>Email-<b>{conEmail}</b></p>
</div>
<div style="background-color:#7ff6f6;border-style: solid;padding:2%;">
<p>Phone-<b>{conPhone}</b></p>
</div>
@Sunil02kumar
Sunil02kumar / skChildComponent.html
Created February 22, 2024 16:14
Communicate from Parent to Child Component in LWC
<template>
<div style="background-color:#b2b689;border-style: solid;padding:2%;">
<b>Child component</b>
<div style="background-color:#7ff6f6;border-style: solid;padding:2%;">
<p>Getting value from parent using public property @api decorator</p>
<p>URL passed from parent-<b>{passedUrl}</b></p>
</div>
<div style="background-color:#7ff6f6;border-style: solid;padding:2%;">
@Sunil02kumar
Sunil02kumar / SK_CustomMetadataUtility.apxc
Created December 23, 2023 10:38
Export all Custom Metadata Records in CSV file using Apex
public class SK_CustomMetadataUtility {
public static void exportAllCMRecordsInCSV(){
Map<string,List<string>> objToFieldsMap = new Map<string,List<string>>();
Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
for(String ss1: schemaMap.keyset()){
Schema.SObjectType objToken=schemaMap.get(ss1);
//find details about sobject
Schema.DescribeSObjectResult objDescribe=objToken.getdescribe();
string objAPIName= string.valueof(objDescribe.getName());
@Sunil02kumar
Sunil02kumar / SkStandardEmailComposer.html
Created August 20, 2023 08:14
Open Standard Email composer from LWC Component - Global Email Quick Action
<template>
<lightning-card title="Launch Standard Email Composer in LWC">
<div style="background-color:#E6E6FA;border-style: solid;height:200px;margin:5%;padding:2%;">
<lightning-button variant="neutral" label="Send an Email" onclick={onButtonClick}></lightning-button>
</div>
</lightning-card>
</template>
@Sunil02kumar
Sunil02kumar / downloadAllFileScript.apxc
Created August 3, 2023 10:19
Script to generate URL for download all files related to any record
string parentRecordId='0012800001IrqlyAAB';
string orgbaseUrl=URL.getSalesforceBaseUrl().toExternalForm();
string downloadAllFileUrl=orgbaseUrl+'/sfc/servlet.shepherd/version/download';
List<string> contentVersionIdList = new List<string>();
for(ContentDocumentLink cdl:[SELECT ContentDocumentId,ContentDocument.title,ContentDocument.LatestPublishedVersionId FROM ContentDocumentLink where LinkedEntityId =:parentRecordId]){
contentVersionIdList.add(string.valueof(cdl.ContentDocument.LatestPublishedVersionId));
}
downloadAllFileUrl = downloadAllFileUrl +'/'+string.join(contentVersionIdList,'/');
system.debug('***downloadAllFileUrl:'+downloadAllFileUrl);
@Sunil02kumar
Sunil02kumar / SK_ContentVersionTrigger.apxt
Created August 3, 2023 10:16
Remove special characters from file names when uploaded in salesforce
//purpose- remove special characters from file names when uploaded in salesforce
trigger SK_ContentVersionTrigger on ContentVersion (before insert) {
for(ContentVersion cv: trigger.new){
if(string.isNotBlank(cv.Title)){
cv.Title= cv.Title.replaceAll('[^-a-zA-Z0-9\\s+]', '');
System.debug('***updated Title '+cv.Title);
}
}
}
public class SK_ToolingAPIFieldsUtility {
@AuraEnabled
public static DM_FieldWrapper findAllFields(string selOrgNCName,string objAPIName,string NamespacePrefix){
DM_FieldWrapper returnValue= new DM_FieldWrapper();
string URIForFields='/services/data/v54.0/tooling/query/?q=Select+id,Datatype,ReferenceTo,ExtraTypeInfo,IsCalculated,IsCompound,IsIndexed,ValueTypeId,RelationshipName,NamespacePrefix,Label,IsNameField,QualifiedApiName,developerName+from+FieldDefinition+';
URIForFields=URIForFields + 'where+EntityDefinition.QualifiedApiName=\''+objAPIName+'\'+AND+IsCalculated=false+';
URIForFields=URIForFields + '+AND+DataType!=\'Auto+Number\'';
string endpointURL='callout:'+selOrgNCName+URIForFields;
public class SK_ToolingAPIUtility {
@AuraEnabled
public static List<checkboxGroupValuesWrapper> findAllObjects(string selOrgNCName,string namespacePrefix,string objName){
system.debug('****selOrgNCName:'+selOrgNCName);
system.debug('****NamespacePrefix:'+namespacePrefix);
system.debug('****objName:'+objName);
List<checkboxGroupValuesWrapper> returnList=new List<checkboxGroupValuesWrapper>();
try {
@Sunil02kumar
Sunil02kumar / skChildCmp.html
Created March 26, 2023 07:09
Custom Events in LWC
<template>
<h1>Click below buttons to get URL for resources</h1>
<lightning-button label="SFDCSTUFF BLOGS" onclick={sendMessageToParentCmp}></lightning-button>
<lightning-button label="TRAILHEAD" onclick={sendMessageToParentCmp}></lightning-button>
</template>
@Sunil02kumar
Sunil02kumar / skAccountHierarchyCmp.html
Last active May 2, 2023 08:24
Account Hierarchy Using Tree Grid in LWC
<template>
<div>
<lightning-card title="Account Hierarcy">
<lightning-tree-grid
columns={gridColumns}
data={gridData}
key-field="Id"
hide-checkbox-column="true"
expanded-rows={currentExpandedRows}>
</lightning-tree-grid>