Skip to content

Instantly share code, notes, and snippets.

View surajp's full-sized avatar
😄
Focusing

Suraj Pillai surajp

😄
Focusing
View GitHub Profile
@surajp
surajp / designer.html
Last active August 29, 2015 14:18
designer
<link rel="import" href="../../salesforce/mobile-ui-elements/elements/force-sobject/force-sobject.html">
<link rel="import" href="../../salesforce/mobile-ui-elements/elements/force-ui-list/force-ui-list.html">
<polymer-element name="my-element">
<template>
<style>
:host {
position: absolute;
width: 100%;
@surajp
surajp / Business-Hours.txt
Created May 25, 2019 16:45
Calculate Business Hours between 2 given date times in Salesforce
FLOOR((suraj__Actual_End_Date__c - suraj__Actual_Start_Date__c)/7)*5*9 +
MIN(5,FLOOR(MOD((suraj__Actual_End_Date__c - suraj__Actual_Start_Date__c),7)))*9+
IF((TIMEVALUE(suraj__Actual_End_Date__c)-TIMEVALUE("12:00:00.00"))/(3600*1000)>16,0,MIN(9,(TIMEVALUE(suraj__Actual_End_Date__c)-TIMEVALUE("12:00:00.00"))/(3600*1000))) - IF((TIMEVALUE(suraj__Actual_Start_Date__c)-TIMEVALUE("12:00:00.00"))/(3600*1000)>16,0,MIN(9,(TIMEVALUE(suraj__Actual_Start_Date__c)-TIMEVALUE("12:00:00.00"))/(3600*1000)))
@surajp
surajp / create js ContentVersion
Created July 3, 2019 03:12
Create Content Version using uiRecordApi in LWC
import {createRecord} from 'lightning/uiRecordApi';
const fileData={
Title:'Test File',
PathOnClient:'myfile.txt',
VersionData: window.btoa('Hello,World'),
Description:'test file'
}
const payload={apiName:'ContentVersion',fields:fileData};
createRecord(payload);
@surajp
surajp / regexvaljsonarray
Last active July 5, 2019 00:11
Regex validation for JSON Array
const colheaders = Object.keys(rows[0]);
const errors=[];
const regexpArray=[];
rows.forEach((row,rowindex)=>{
errors[rowindex]=[];
Object.values(row).forEach((val,colindex)=>{
if(regexpArray[colindex] && regexpArray[colindex].test(val)){
errors[rowindex].push(colheaders[colindex]);
}
})
@surajp
surajp / escapeNewlineCsv.js
Created July 9, 2019 05:49
Escape new line character within the same row in csv
const cleanFunction = arr=>arr.reduce((clean,current)=>{current.replace(/[^(?<!\\)"]/g,"").length%2>0?clean+=current+"\\n":clean+=current+"\n";return clean},"").replace(/\\n$/,'')
@surajp
surajp / standardValSet.xml
Created July 11, 2019 15:15
package xml for pulling standard and global picklists
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>Standard & Global Picklists</fullName>
<types>
<members>*</members>
</types>
<types>
<members>Industry</members>
<members>AccountContactRole</members>
<members>AccountOwnership</members>
@surajp
surajp / ImageToBase64.cls
Last active July 20, 2019 02:28
Convert images in rich text areas that are references to a Document, to base64 for exporting
/**
* This code is untested.
* Assumes references to images in rich text fields is in the form of 'https://<url>/<documentId>' and refers to a document record
*/
public class ImageToBase64{
public void convertToBase64(Id[] recordIds){
Account[] accts = new Account[]{};
Map<Id,Id[]> acctDocMap = new Map<Id,Id[]>();
Map<Id,Document> docMap = new Map<Id,Document>();
@surajp
surajp / destructiveChanges.xml
Created July 22, 2019 19:29
Destructive Changes for deleting standard page layouts from a new scratch org
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>layouts</fullName>
<types>
<members>Account-Account %28Marketing%29 Layout</members>
<members>Account-Account %28Sales%29 Layout</members>
<members>Account-Account %28Support%29 Layout</members>
<members>Case-Case %28Marketing%29 Layout</members>
<members>Case-Case %28Sales%29 Layout</members>
<members>Case-Case %28Support%29 Layout</members>
@surajp
surajp / webpack.config.js
Created November 6, 2019 21:20
basic webpack config
const path = require('path');
module.exports = {
mode: "production",
entry: "./src/index",
output: {
// options related to how webpack emits results
path: path.resolve(__dirname, "dist"), // string
// the target directory for all output files
// must be an absolute path (use the Node.js path module)
@surajp
surajp / flatten.js
Created December 24, 2019 05:21
Utility function for flattening Objects
const flatten = (obj,newobj,prefix)=>{
if(!newobj)newobj={};
for(let prop in obj){
if(!prefix)prefix='';
if(typeof obj[prop]==='object')
flatten(obj[prop],newobj,prefix+prop);
else
newobj[prefix+prop] = obj[prop];
}
return newobj;