Skip to content

Instantly share code, notes, and snippets.

@zaki-yama
zaki-yama / directory_tree
Created July 14, 2015 15:45
aglioを使ったAPIドキュメント作成用のgulpfile
# ディレクトリ構成
├── apidocs
│ ├── api.md
│ ├── layout.md
│ └── questions.md
├── gulpfile.js
├── package.json
└── published
├── index.html
└── index.md
@zaki-yama
zaki-yama / ComponentController.cls
Last active August 29, 2015 14:24
[Salesforce]スケジュール済みApexでVisualforceページをpdf化
public class ComponentController {
public String opportunityId {get; set;}
public Opportunity getOpp() {
System.debug(LoggingLevel.INFO, this.opportunityId);
return [
SELECT
Name,
@zaki-yama
zaki-yama / Security.settings
Last active August 29, 2015 14:24
[Salesforce]パスワードポリシーをForce.com Migration Toolで設定する
<?xml version="1.0" encoding="UTF-8"?>
<SecuritySettings xmlns="http://soap.sforce.com/2006/04/metadata">
<passwordPolicies>
<!-- historyRestriction が 0 だと expiration は Never にできない -->
<expiration>Never</expiration>
<historyRestriction>3</historyRestriction>
</passwordPolicies>
</SecuritySettings>
@zaki-yama
zaki-yama / apiary.apib
Created July 4, 2015 16:01
apiary.apibを複数ファイルに分割する
FORMAT: 1A
HOST: http://polls.apiblueprint.org/
# MyFirstAPI
Polls is a simple API allowing consumers to view polls and vote in them.
@zaki-yama
zaki-yama / HttpCallout.cls
Last active August 29, 2015 14:23
[Salesforce]スケジュールApexでVisualforceをpdf送信
public class HttpCallout {
@future(callout=true)
public static void sendVF() {
// 名前空間を指定していると /services/apexrest/[namespace]/sendPDFEmail となる
String serviceUrl = '/services/apexrest/sendPDFEmail';
String endpoint = URL.getSalesforceBaseUrl().toExternalForm() + serviceUrl;
HttpRequest req = new HttpRequest();
req.setEndpoint(endpoint);
@zaki-yama
zaki-yama / OpportunityPage.html
Last active August 29, 2015 14:23
[Salesforce]Visualforceをpdf出力するサンプル
<apex:page renderAs="pdf" standardController="Opportunity" showHeader="false" sidebar="false" applyBodyTag="false" applyHtmlTag="false">
<html>
<head>
<style>
@page {
size: 8.27in 11.69in;
margin: 10px;
}
body {
font-family: 'Arial Unicode MS';
@zaki-yama
zaki-yama / SendEmail.cls
Created June 24, 2015 07:30
[Apex]メール送信時に「活動履歴」にも残す
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
// この書き方だと活動履歴には残らない
// String[] toAddresses = new String[] { [Toに指定したいアドレス] };
// mail.setToAddresses(toAddresses);
Contact to = [SELECT Id FROM Contact WHERE Id = ...];
mail.setTargetObjectId(c.Id);
List<String> ccAddresses = new List<String> { [Ccに指定したいアドレス] };
@zaki-yama
zaki-yama / SendEmailWithAttachments.cls
Last active August 29, 2015 14:23
[Apex]添付ファイルつきメール送信のサンプル
/**
* 添付ファイルつきのメールを送信するサンプル
*/
// メール
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(new List<String> { '[email protected]' });
mail.setSubject('Mail Subject');
mail.setPlainTextBody('Mail body');
@zaki-yama
zaki-yama / CRUDandFLS.cls
Last active August 29, 2015 14:21
[Salesforce]ApexでCRUD/FLSのチェック
// すべてのSObjectを取得する場合
Map<String, Schema.SObjectType> sMap = Schema.getGlobalDescribe();
// SObjectの種類を指す
Schema.SObjectType eventType = Event.SObjectType;
// または、インスタンスから取得
SObject sObj = new Account();
Schema.SObjectType accountType = sObj.getSObjectType();
// Schema.DescribeSObjectResultというクラスを経由する
@zaki-yama
zaki-yama / DeleteMulti.js
Created May 8, 2015 10:20
Salesforce: リストビューに一括削除ボタン
{!REQUIRESCRIPT('/soap/ajax/33.0/connection.js')};
var ids = {!GETRECORDIDS($ObjectType.Lead)},
idsStr = ids.toString().replace(/,/g, "','");
query = "SELECT Name FROM Lead WHERE Id IN ('" + idsStr + "')",
records = sforce.connection.query(query).getArray('records');
if (records.length === 0) {
alert('1つ以上選択してください');
} else {