Skip to content

Instantly share code, notes, and snippets.

@tarot
tarot / FindHelper.cls
Last active July 8, 2016 02:36
PicklistとMultiPicklistとTextかTextAreaな数式項目の値を、指定したLongTextArea項目に連結してコピーする。SOSLはこれらの項目を検索できないので。トランスレーションには無力(最後に更新した時のユーザ言語で保存される)。`NOW()`関数や親レコードを参照する数式にも無力(最後に更新した時の値で保存される)
public without sharing class FindHelper {
private static Map<Schema.SObjectType, Schema.SObjectField[]> fieldCache = new Map<Schema.SObjectType, Schema.SObjectField[]>();
public static void beforeSave(SObject[] xs, Schema.SObjectField searchField) {
Schema.SObjectField[] copyingFields = copyingFieldsOf(xs.getSObjectType());
Integer length = searchField.getDescribe().getLength();
for (SObject e : xs) {
putSearchField(e, copyingFields, searchField, length);
}
@tarot
tarot / sample.page
Created July 30, 2015 08:04
ページ内の最初の利用がinputField/outputFieldだった変数は、そのページ内ではObject型として扱われる模様。なんでもいいから先にinputField/outputField以外で出力すれば通った
<apex:page standardController="Account">
<div style="display: none;">{!Account.CreatedDate}</div>
<apex:outputField value="{!Account.CreatedDate}"/>
<apex:outputText value="{0,date}">
<apex:param value="{!Account.CreatedDate}"/>
</apex:outputText>
</apex:page>
@tarot
tarot / SampleExtension.cls
Created July 30, 2015 07:48
何故かこれは通る。{!Account.CreatedDate}と{!record.CreatedDate}が逆でもOK
public class SampleExtension {
public Account record { get; private set; }
public SampleExtension(ApexPages.StandardController controller) {
record = (Account) controller.getRecord();
}
}
@tarot
tarot / sample.page
Created July 30, 2015 06:57
何でこれがエラーになるの? "<apex:outputText> の値属性の形式が無効です。正数であり、データ型が数値、日付、時刻、または選択である必要があります。" ???
<apex:page standardController="Account">
<apex:outputField value="{!Account.CreatedDate}"/>
<apex:outputText value="{0,date}">
<apex:param value="{!Account.CreatedDate}"/>
</apex:outputText>
</apex:page>
@tarot
tarot / Strings.cls
Last active August 29, 2015 14:24
JavaScript style String::replace for Apex (Salesforce)
public class Strings {
public interface Replacer {
String apply(String match, String[] p, Integer offset, String str);
}
public static String replaceFirst(String str, String regExp, Replacer replacement) {
return replaceFirst(str, Pattern.compile(regExp), replacement);
}
@tarot
tarot / gulpfile.coffee
Created July 9, 2015 13:47
なんで"sourcesContent":[null]になるの?
gulp = require 'gulp'
sass = require 'gulp-sass'
sourcemaps = require 'gulp-sourcemaps'
gulp.task 'sass', ->
gulp.src './source/**/*.sass'
.pipe sourcemaps.init()
.pipe sass(indentedSyntax: true).on('error', sass.logError)
.pipe sourcemaps.write('.')
.pipe gulp.dest('./public')
$ ->
$('input[type="file"]').on 'change', (event) ->
reader = new FileReader()
reader.onload = ->
boundary = "ljfdshflashdlfkjaklsdfjlksadjflksajdflksajdklfas"
blob = new Blob [
[
"--#{boundary}"
'Content-Disposition: form-data; name="json"'
'Content-Type: application/json; charset=UTF-8'
@tarot
tarot / package.json
Created June 19, 2015 11:26
ProfileのfieldPremissionとobjectPermissionを全部trueにする
{
"dependencies": {
"bluebird": "^2.9.9",
"commander": "^2.7.1",
"dotenv": "^0.5.1",
"glob": "^5.0.3",
"jsforce": "^1.4.0",
"jszip": "^2.5.0",
"lodash": "^3.5.0",
"shelljs": "^0.4.0",
@tarot
tarot / heroku_up.sh
Last active August 29, 2015 14:22
web dynoをスケールするコマンド。事前にheroku config:setでHEROKU_API_KEYとHEROKU_APP_NAMEを設定する。
curl -n -X PATCH https://api.heroku.com/apps/${HEROKU_APP_NAME}/formation/web \
-H "Accept: application/vnd.heroku+json; version=3" \
-H "Authorization: Bearer ${HEROKU_API_KEY}" \
-H "Content-Type: application/json" \
-d '{"quantity":1}'
# https://github.com/heroku/rack-timeout/issues/76
class TimeoutRecovery
def initialize(app, options = {})
@app, @options = app, options
end
# Rack::Timeout, as of 0.2.4, raises errors that descend from the Exception
# class when a request takes too long - however, this is a very strong
# exception level and will kill Puma's worker if we let it continue down the