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 / iFrame.js
Last active November 18, 2023 14:05
JS code for iFrame LWC
import { api, LightningElement } from 'lwc';
export default class IFrame extends LightningElement {
@api height = '500px';
@api sandbox = '';
@api url = '';
@api width = '100%';
renderedCallback() {
if (this.sandbox) {
@svierk
svierk / iFrame.js-meta.xml
Last active November 18, 2023 14:09
XML file for iFrame 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>iFrame</masterLabel>
<description>Configurable iFrame</description>
<targets>
<target>lightning__AppPage</target>
<target>lightning__HomePage</target>
<target>lightning__FlowScreen</target>
@svierk
svierk / csvToDatatable.html
Last active October 19, 2022 06:21
Lightning Input for CSV File Upload
<template>
<lightning-input
type="file"
label="Please upload a UTF-8 encoded, comma separated .csv file"
accept=".csv"
onchange={handleFileUpload}
>
</lightning-input>
</template>
@svierk
svierk / csvToDatatable.js
Last active October 18, 2022 18:04
JS Controller to process CSV File Upload
import { LightningElement } from 'lwc';
export default class CsvToDatatable extends LightningElement {
handleFileUpload(event) {
const files = event.detail.files;
if (files.length > 0) {
const file = files[0];
// start reading the uploaded csv file
@svierk
svierk / csvToDatatable.js
Last active October 23, 2022 15:10
Parsing Logic for simple CSV File Upload
parse(csv) {
// parse the csv file and treat each line as one item of an array
const lines = csv.split(/\r\n|\n/);
// parse the first line containing the csv column headers
const headers = lines[0].split(',');
// iterate through csv headers and transform them to column format supported by the datatable
this.columns = headers.map((header) => {
return { label: header, fieldName: header };
@svierk
svierk / csvToDatatable.html
Last active October 23, 2022 15:09
HTML Template for CSV Parser LWC
<template>
<lightning-card title="CSV To Datatable" icon-name="doctype:csv">
<div class="slds-p-around_medium">
<lightning-input
type="file"
label="Please upload a UTF-8 encoded, comma separated .csv file"
accept=".csv"
onchange={handleFileUpload}
>
</lightning-input>
@svierk
svierk / csvToDatatable.js-meta.xml
Last active November 18, 2023 14:09
XML file for CSV Parser 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>CSV To Datatable</masterLabel>
<description>A simple parser for UTF-8 encoded, comma separated .csv files.</description>
<targets>
<target>lightning__AppPage</target>
<target>lightning__HomePage</target>
<target>lightning__RecordPage</target>
@svierk
svierk / openRecordPageFlowAction.js
Created December 11, 2022 14:21
JS code for Open Record Page Flow Action LWC
import { api, LightningElement } from 'lwc';
export default class OpenRecordPageFlowAction extends LightningElement {
@api recordId;
@api target = '_blank';
connectedCallback() {
const completeURL = `${window.location.origin}/${this.recordId}`;
window.open(completeURL, this.target);
}
@svierk
svierk / openRecordPageFlowAction.html
Created December 11, 2022 14:23
HTML Template for Open Record Page Flow Action LWC
<template>
<lightning-spinner alternative-text="Loading" size="medium"></lightning-spinner>
</template>
@svierk
svierk / openRecordPageFlowAction.js-meta.xml
Last active November 18, 2023 14:09
XML file for Open Record Page Flow Action 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>Open Record Page Flow Action</masterLabel>
<description>Component to forward to a record page from flow.</description>
<targets>
<target>lightning__FlowScreen</target>
</targets>
<targetConfigs>