Skip to content

Instantly share code, notes, and snippets.

View svierk's full-sized avatar
🏠
Working from home

Sebastiano Schwarz svierk

🏠
Working from home
View GitHub Profile
@svierk
svierk / contentDocumentIcon.html
Created January 25, 2024 18:47
HTML Template for Content Document Icon LWC
<template>
<lightning-icon class="slds-current-color" icon-name={icon} size="small"></lightning-icon>
</template>
@svierk
svierk / contentDocumentTable.html
Last active January 25, 2024 21:02
HTML Template for Content Document Table LWC
<template>
<template lwc:if={isLoading}>
<lightning-spinner alternative-text="Loading" variant="brand"></lightning-spinner>
</template>
<template lwc:if={showCard}>
<lightning-card icon-name={cardIcon} title={cardTitle}>
<c-content-document-table-extension
key-field="id"
columns={columns}
data={documents}
@svierk
svierk / contentDocumentPreview.html
Created January 25, 2024 14:46
HTML Template for Content Document Preview LWC
<template>
<a onclick={showPreview}>{preview.name}</a>
</template>
@svierk
svierk / contentDocumentPreview.js
Created January 25, 2024 14:27
JS Code for Content Document Preview LWC
import { CurrentPageReference, NavigationMixin } from 'lightning/navigation';
import { LightningElement, api, wire } from 'lwc';
export default class ContentDocumentPreview extends NavigationMixin(LightningElement) {
@wire(CurrentPageReference) pageRef;
@api preview;
showPreview() {
this[NavigationMixin.Navigate]({
type: 'standard__namedPage',
@svierk
svierk / contentDocumentTableExtension.js
Last active January 25, 2024 14:24
JS Code for Content Document Table Extension LWC
import LightningDatatable from 'lightning/datatable';
import contentDocumentIcon from './contentDocumentIcon.html';
import contentDocumentPreview from './contentDocumentPreview.html';
export default class ContentDocumentTableExtension extends LightningDatatable {
static customTypes = {
contentDocumentIcon: {
template: contentDocumentIcon,
standardCellLayout: true,
typeAttributes: ['icon']
@svierk
svierk / ContentDocumentController.cls
Created January 24, 2024 19:50
Apex Class for Content Document Table Component | getLatestVersion
@AuraEnabled
public static string getLatestVersion(Id recordId) {
return [
SELECT Id, IsLatest, Title, ContentDocumentId
FROM ContentVersion
WHERE ContentDocumentId = :recordId AND isLatest = TRUE
WITH USER_MODE
LIMIT 1
]
.Id;
@svierk
svierk / ContentDocumentController.cls
Created January 24, 2024 19:49
Apex Class for Content Document Table Component | getDocuments
@AuraEnabled(cacheable=true)
public static String getDocuments(String library, String folder, Id recordId) {
try {
String folderName = folder != null ? folder : recordId.getSObjectType().getDescribe().getName();
// get workspace library
ContentWorkspace cw = [
SELECT Id, Name
FROM ContentWorkspace
WHERE Name LIKE :library
@svierk
svierk / ContentDocumentControllerTest.cls
Last active January 24, 2024 19:17
Apex Test Class for Content Document Table Component | Test Setup & Test Cases
@TestSetup
static void makeData() {
User u = new User();
u.FirstName = 'Test';
u.LastName = 'User';
u.Username = '[email protected]';
u.Alias = '123test';
u.Email = '[email protected]';
u.ProfileId = [SELECT Id FROM Profile WHERE Name = 'System Administrator' LIMIT 1].Id;
u.TimeZoneSidKey = 'America/Chicago';
@svierk
svierk / ContentDocumentControllerTest.cls
Last active January 23, 2024 22:36
Apex Test Class for Content Document Table Component | Content Setup
private static Id createContentSetup(Id recordId) {
ContentWorkspace cw = getContentWorkspace('Test Documents');
insert cw;
ContentFolderLink cfl = [
SELECT Id, ContentFolderId, ParentEntityId
FROM ContentFolderLink
WHERE ParentEntityId = :cw.Id
];
ContentFolder cf = getContentFolder(recordId.getSObjectType().getDescribe().getName(), cfl.ContentFolderId);
insert cf;
@svierk
svierk / dragAndDrop.js
Last active January 3, 2024 08:21
JS Code for Drag & Drop Demo LWC | Event Handler
handleDragStart(event) {
event.dataTransfer.setData('id', event.target.dataset.id);
event.dataTransfer.setData('label', event.target.dataset.name);
}
handleDragOver(event) {
event.preventDefault();
event.currentTarget.style = 'background-color: pink; border-color:red;';
}