Skip to content

Instantly share code, notes, and snippets.

View arufian's full-sized avatar
🌏
Working from home, cafe, hotel, etc

Alfian Busyro arufian

🌏
Working from home, cafe, hotel, etc
View GitHub Profile
@arufian
arufian / gist:35b7734880230365565c131ab5e22e91
Created December 23, 2022 09:57
a fetch function with oauth 2.0 capability
function fetchWithAuth(url, options) {
var accessToken = '<your access token>';
if (!options) {
options = {};
}
if (!options.headers) {
options.headers = new Headers();
}
options.headers.append('Authorization', 'Bearer ' + accessToken);
return fetch(url, options);
@arufian
arufian / dynamicFields.js
Last active February 25, 2024 22:19
How to use dynamic fields at @wire getRecord - LWC (Lightning Web Component)
import { LightningElement, track, wire, api } from 'lwc';
export default class DynamicFields extends LightningElement {
@api recordId;
@track fields;
@api objectApiName;
@wire(getRecord, { recordId: '$recordId', fields: '$fields' })
record;
@arufian
arufian / gist:528f70452178efc527fb
Created January 26, 2015 10:31
List All not yet approved "Approval list"
<apex:page >
<apex:includeScript value="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"/>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
<script>
var statusList = {
'Started': '?',
'Pending': 'Pending',
'Approved': 'Approved'
}
@arufian
arufian / gist:197fc5ae7a1014fe61bb
Last active August 29, 2015 14:14
Yet Another Salesforce REST API with JS
// refs: http://www.jitendrazaa.com/blog/salesforce/salesforce-rest-api-playground/
function getQueryStringValue (key) {
return unescape(window.location.search.replace(new RegExp("^(?:.*[&\\?]" + escape(key).replace(/[\.\+\*]/g, "\\$&") + "(?:\\=([^&]*))?)?.*$", "i"), "$1"));
}
{!REQUIRESCRIPT ("/soap/ajax/13.0/connection.js")};
var records = {!GETRECORDIDS($ObjectType.Book__c)};
var counter = 0;
for(var i=0; i<records.length; i++){
var xmlhttp = new XMLHttpRequest();
@arufian
arufian / gist:4822bedfe533e6527257
Created December 24, 2014 02:16
Git log pretty
git config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative"
trigger BookTrigger on Book__c (after insert, after update) {
BookTriggerHandler handler = new BookTriggerHandler();
if (Trigger.isBefore) {
// before trigger logic
} else if (Trigger.isAfter) {
if (Trigger.isInsert) {
// GoogleBooksAPIで書籍の情報を取得
handler.setGoogleBooksInfo(Trigger.new);
@arufian
arufian / gist:cf773069d7f9ecd0b33a
Last active August 29, 2015 14:08
To make a new line (<br />) on the text every 10 chars
function binSearch(text, searchLen) {
var left = 0, right = text.length;
var breakPos = left, lastBreakPos = right;
while (Math.abs(lastBreakPos - breakPos) > 1) {
lastBreakPos = breakPos;
breakPos = Math.floor((left+right)/2);
if (searchLen < getTextWidth(text.substring(0, breakPos)))
right = breakPos - 1;
else
left = breakPos + 1;

Sublime Text 2 – Useful Shortcuts (PC)

Loosely ordered with the commands I use most towards the top. Sublime also offer full documentation.

Editing

Ctrl+C copy current line (if no selection)
Ctrl+X cut current line (if no selection)
Ctrl+⇧+K delete line
Ctrl+↩ insert line after
@arufian
arufian / withMethod.cls
Last active August 29, 2015 14:07
Select * in SOQL using Apex Class
String table = 'TableName'; // with __c if use Custom Object
Map<String, Schema.SObjectType> m = Schema.getGlobalDescribe() ;
Schema.SObjectType s = m.get(table) ;
Schema.DescribeSObjectResult r = s.getDescribe() ;
Map<String, Schema.SObjectField> fields = r.fields.getMap() ;
string soql = '';
for (String fieldName : fields.keyset()) {
if (soql != '') {
soql += ', ';
}
global with sharing class CommonClass {
global List<Object> selectAllFromTable(String objectName, String whereCondition, String order, String limit1){
String query = selectAllQuery(objectName, whereCondition);
query += ' ORDER BY '+order+' LIMIT '+limit1;
try {
return database.query(query);
} catch (QueryException e){
//perform exception handling
System.debug('failed to selectAllFromTable');