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 / formatDateTime.js
Last active August 14, 2020 13:34
Format JS date to ISO 8601 date time representation (YYYY-MM-DDThh:mm:ss.sTZD) in UTC
const formatToTwoDigits = (input)=>input?input.toString().padStart(2,'0'):null
const formatToDateTime = (inpDate) => inpDate && inpDate instanceof Date ? `${inpDate.getUTCFullYear()}-${formatToTwoDigits(inpDate.getUTCMonth()+1)}-${formatToTwoDigits(inpDate.getUTCDate())}T${formatToTwoDigits(inpDate.getUTCHours())}:${formatToTwoDigits(inpDate.getUTCMinutes())}:${formatToTwoDigits(inpDate.getUTCSeconds())}.${inpDate.getMilliseconds().toFixed(3)}Z`:null
/************************************************************
*** @author: Suraj Pillai
*** @description: A universal class for mocking in tests. Contains a method for setting the return value for any method. Another method returns the number of times a method was called
*/
@isTest
public with sharing class UniversalMocks implements System.StubProvider {
public static Map<String, Object> returnValuesMap = new Map<String, Object>();
public static Map<String, Integer> callCountsMap = new Map<String, Integer>();
global class Exporter implements System.Schedulable {
global void execute(SchedulableContext sc) {
ApexPages.PageReference report = new ApexPages.PageReference('/00O500000000000?csv=1');
Messaging.EmailFileAttachment attachment = new Messaging.EmailFileAttachment();
attachment.setFileName('report.csv');
attachment.setBody(report.getContent());
attachment.setContentType('text/csv');
Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
message.setFileAttachments(new Messaging.EmailFileAttachment[] { attachment } );
message.setSubject('Report');

Keybase proof

I hereby claim:

  • I am surajp on github.
  • I am surajp (https://keybase.io/surajp) on keybase.
  • I have a public key whose fingerprint is E697 5288 01FE 150B 3247 E81C A286 046F 8195 E8D9

To claim this, I am signing this object:

<template>
<div class="slds-p-around_small">
<lightning-input label="Object Name" onchange={changeName}></lightning-input>
<lightning-input label="My Domain" onchange={changeDomain}></lightning-input>
<lightning-helptext content="Use document.cookie.match(/sid=([^;]*)/)[1] in the browser console after logging into SF" class="slds-p-right_xx-small"></lightning-helptext>
<lightning-input label="SessionId" onchange={changeSessionId}>
</lightning-input>
<lightning-textarea label="CSV Data"></lightning-textarea>
<lightning-button onclick={upload} label="upload"></lightning-button>
@surajp
surajp / 15to18.js
Last active May 7, 2020 21:59
Convert SF 15 char to 18 char id
(inp) =>
((elements) =>
inp.length != 15
? Error("invalid id")
: inp +
Object.values(elements)
.map((a) => "ABCDEFGHIJKLMNOPQRSTUVWXYZ012345".charAt(a))
.join(""))(
inp.split("").reduce(
(op, curr, index) => {
@surajp
surajp / DeleteLogsAnon.java
Last active May 11, 2024 03:17
Delete Apex Logs
HttpRequest request = new HttpRequest();
request.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionID());
request.setMethod('DELETE');
Http sender = new Http();
for(ApexLog log: [Select Id from ApexLog]){
request.setEndpoint(URL.getSalesforceBaseUrl().toExternalForm()+'/services/data/v36.0/tooling/sobjects/ApexLog/'+log.Id+'/');
sender.send(request);
}
@surajp
surajp / CSVColIterator.cls.java
Created April 10, 2020 00:12
CSV Column Iterator
public class CSVColIterator implements Iterator<String> {
private String colDelimiter=',';
private String textQualifier='"';
private String row='';
private Integer currentIndex=0;
public CSVColIterator(String row){
this.row = row;
}
@surajp
surajp / CheckFeatureController.cls
Created April 3, 2020 01:40
Check Feature in lwc
public with sharing class CheckFeatureController {
@AuraEnabled
public static boolean checkFeature(String featureName){
return FeatureManagementCheckerFactory.getFeatureManagementChecker().checkPermission(featureName);
}
}
@surajp
surajp / uniq.js
Last active March 31, 2020 21:07
Remove duplicate values from an object array with an accessor function to identify dupes
/** Example 1: uniq([
{name:'John',id:1},
{name:'Jane',id:2},
{name:'John',id:3},
{name:'Jack',id:4}
],e=>e.name)= [
{name:'John',id:3},
{name:'Jane',id:2},
{name:'Jack',id:4}
]