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 / takeUserProfilePicture.js
Created February 12, 2024 17:02
JS Code for Take User Profile Picture LWC
export default class TakeUserProfilePicture extends LightningElement {
video;
canvas;
renderedCallback() {
this.video = this.template.querySelector('.video');
this.canvas = this.template.querySelector('.canvas');
}
async startCamera() {
@svierk
svierk / takeUserProfilePicture.html
Created February 12, 2024 16:53
HTML Template for Take User Profile Picture LWC
<template>
<lightning-card icon-name="custom:custom38" title="Take User Profile Picture">
<div class="slds-grid slds-gutters">
<div class="slds-col slds-size_1-of-2">
<video class="slds-p-left_small video" autoplay></video>
<canvas class="slds-hide canvas"></canvas>
</div>
<div class="slds-col slds-size_1-of-2">
<img src="" class="slds-p-right_small slds-hide preview" alt="Captured User Photo" />
</div>
@svierk
svierk / UserProfilePictureController.cls
Created February 12, 2024 15:18
Apex Controller class for updating the user's profile picture
public with sharing class UserProfilePictureController {
@AuraEnabled
public static void updateProfilePicture(String base64) {
try {
Blob b = EncodingUtil.base64Decode(base64);
ConnectApi.BinaryInput binaryInput = new ConnectApi.BinaryInput(b, 'image/png', 'UserPhoto.png');
ConnectApi.UserProfiles.setPhoto(null, 'me', binaryInput);
} catch (Exception e) {
System.debug('The following exception has occurred: ' + e.getMessage());
}
@svierk
svierk / contentDocumentTable.js
Last active January 27, 2024 10:55
JS Code for Content Document Table LWC | Columns & Data
export default class ContentDocumentTable extends NavigationMixin(LightningElement) {
@api recordId = null;
@api library = 'Documents';
@api folder = null;
@api showCard = false;
@api cardIcon = 'standard:file';
@api cardTitle = 'Document Table';
@api showDownloadAction = false;
@api showViewAction = false;
@api showDeleteAction = false;
@svierk
svierk / contentDocumentTable.js
Created January 27, 2024 08:13
JS Code for Content Document Table LWC | Configuration
const ICONS = {
csv: 'doctype:csv',
default: 'doctype:attachment',
docx: 'doctype:word',
jpeg: 'doctype:image',
jpg: 'doctype:image',
pdf: 'doctype:pdf',
png: 'doctype:image',
pptx: 'doctype:ppt',
rtf: 'doctype:rtf',
@svierk
svierk / contentDocumentTable.js
Last active January 27, 2024 17:05
JS Code for Content Document Table LWC | Row Actions
addRowActions() {
const actions = [];
if (this.showDownloadAction) actions.push({ label: 'Download', name: 'download' });
if (this.showViewAction) actions.push({ label: 'View', name: 'view' });
if (this.showDeleteAction) actions.push({ label: 'Delete', name: 'delete' });
if (actions.length) {
this.columns.push({ type: 'action', typeAttributes: { rowActions: actions, menuAlignment: 'right' } });
}
}
@svierk
svierk / contentDocumentTable.js-meta.xml
Created January 26, 2024 06:01
XML file for Content Document Table LWC
<?xml version="1.0" encoding="UTF-8" ?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>59.0</apiVersion>
<isExposed>true</isExposed>
<masterLabel>Content Document Table</masterLabel>
<description>A generic table to show shared documents from a Salesforce Files library.</description>
<targets>
<target>lightning__AppPage</target>
<target>lightning__FlowScreen</target>
<target>lightning__HomePage</target>
@svierk
svierk / contentDocumentTable.js
Last active January 27, 2024 11:41
JS Code for Content Document Table LWC | formatSize
formatSize(size) {
return size && size / 1000000 >= 1 ? `${(size / 1000000).toFixed(1)} MB` : `${parseInt(size / 1000, 10)} KB`;
}
@svierk
svierk / contentDocumentIcon.html
Created January 25, 2024 20:50
HTML Template for Content Document Icon Custom Data Type
<template>
<c-content-document-icon icon={value}></c-content-document-icon>
</template>
@svierk
svierk / contentDocumentIcon.js
Created January 25, 2024 18:53
JS Code for Content Document Icon LWC
export default class ContentDocumentIcon extends LightningElement {
@api icon;
}