2010年12月30日木曜日

正規表現構文の要約

正規表現構文の要約

構文 マッチ対象

文字
x 文字 x
\\ バックスラッシュ文字
\0n 8 進値 0n を持つ文字 (0 <= n <= 7)
\0nn 8 進値 0nn を持つ文字 (0 <= n <= 7)
\0mnn 8 進値 0mnn を持つ文字 (0 <= m <= 3、0 <= n <= 7)
\xhh 16 進値 0xhh を持つ文字
\uhhhh 16 進値 0xhhhh を持つ文字
\t タブ文字 ('\u0009')
\n 改行文字 ('\u000A')
\r キャリッジリターン文字 ('\u000D')
\f 用紙送り文字 ('\u000C')
\a 警告 (ベル) 文字 ('\u0007')
\e エスケープ文字 ('\u001B')
\cx x に対応する制御文字

文字クラス
[abc] a、b、または c (単純クラス)
[^abc] a、b、c 以外の文字 (否定)
[a-zA-Z] a ~ z または A ~ Z (範囲)
[a-d[m-p]] a ~ d、または m ~ p: [a-dm-p] (結合)
[a-z&&[def]] d、e、f (交差)
[a-z&&[^bc]] b と c を除く a ~ z: [ad-z] (減算)
[a-z&&[^m-p]] m ~ p を除く a ~ z: [a-lq-z] (減算)

定義済みの文字クラス
. 任意の文字 (行末記号とマッチする場合もある)
\d 数字: [0-9]
\D 数字以外: [^0-9]
\s 空白文字: [ \t\n\x0B\f\r]
\S 非空白文字: [^\s]
\w 単語構成文字: [a-zA-Z_0-9]
\W 非単語文字: [^\w]

POSIX 文字クラス (US-ASCII のみ)
\p{Lower} 小文字の英字: [a-z]
\p{Upper} 大文字の英字: [A-Z]
\p{ASCII} すべての ASCII 文字: [\x00-\x7F]
\p{Alpha} 英字: [\p{Lower}\p{Upper}]
\p{Digit} 10 進数字: [0-9]
\p{Alnum} 英数字: [\p{Alpha}\p{Digit}]
\p{Punct} 句読文字: !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~ のいずれか
\p{Graph} 表示できる文字: [\p{Alnum}\p{Punct}]
\p{Print} プリント可能文字: [\p{Graph}\x20]
\p{Blank} 空白またはタブ: [ \t]
\p{Cntrl} 制御文字: [\x00-\x1F\x7F]
\p{XDigit} 16 進数字: [0-9a-fA-F]
\p{Space} 空白文字: [ \t\n\x0B\f\r]

java.lang.Character クラス (単純な java 文字タイプ)
\p{javaLowerCase} java.lang.Character.isLowerCase() と等価
\p{javaUpperCase} java.lang.Character.isUpperCase() と等価
\p{javaWhitespace} java.lang.Character.isWhitespace() と等価
\p{javaMirrored} java.lang.Character.isMirrored() と等価

Unicode ブロックとカテゴリのクラス
\p{InGreek} ギリシャ語ブロックの文字 (単純ブロック)
\p{Lu} 大文字 (単純カテゴリ)
\p{Sc} 通貨記号
\P{InGreek} ギリシャ語ブロック以外の文字 (否定)
[\p{L}&&[^\p{Lu}]] 大文字以外の文字 (減算)

境界正規表現エンジン
^ 行の先頭
$ 行の末尾
\b 単語境界
\B 非単語境界
\A 入力の先頭
\G 前回のマッチの末尾
\Z 最後の行末記号がある場合は、それを除く入力の末尾
\z 入力の末尾

最長一致数量子
X? X、1 または 0 回
X* X、0 回以上
X+ X、1 回以上
X{n} X、n 回
X{n,} X、n 回以上
X{n,m} X、n 回以上、m 回以下

最短一致数量子
X?? X、1 または 0 回
X*? X、0 回以上
X+? X、1 回以上
X{n}? X、n 回
X{n,}? X、n 回以上
X{n,m}? X、n 回以上、m 回以下

強欲な数量子
X?+ X、1 または 0 回
X*+ X、0 回以上
X++ X、1 回以上
X{n}+ X、n 回
X{n,}+ X、n 回以上
X{n,m}+ X、n 回以上、m 回以下

論理演算子
XY X の直後に Y
X|Y X または Y
(X) X、先方参照を行う正規表現グループ

前方参照
\n マッチした n 番目の先方参照を行う正規表現グループ

引用
\ 正規表現ではないが、次の文字をエスケープする
\Q 正規表現ではないが、\E までのすべての文字をエスケープする
\E 正規表現ではないが、\Q で開始された引用をエスケープする

特殊な構文 (先方参照を行わない)
(?:X) X、先方参照を行わない正規表現グループ
(?idmsux-idmsux) 正規表現ではないが、マッチフラグのオン/オフを切り替える
(?idmsux-idmsux:X) X、指定されたフラグをオン/オフにした先方参照を行わない正規表現グループ
(?=X) X、幅ゼロの肯定先読み
(?!X) X、幅ゼロの否定先読み
(?<=X) X、幅ゼロの肯定後読み
(?(?>X) X、独立した先方参照を行わない正規表現グループ

2010年12月20日月曜日

2010年12月19日日曜日

Constants define

static final Integer INT_CONST1 = 2000;
static final Integer INT_CONST2;
static {
INT_CONST2= 2010;
}

System-defined enums

System.StatusCode
System.XmlTag
System.ApplicationReadWriteMode
System.LoggingLevel
System.RoundingMode
System.SoapType
System.DisplayType
ApexPages.Severity
Dom.XmlNodeType

Maps SOQL Result

Map<ID, Contact> m = new Map<ID, Contact>([select id, lastname
from contact]);

SOSL Find

1)
List<List<sObject>> results = [find {4155557000}
in phone
fields
returning contact(id, phone, firstname, lastname),
lead(id, phone,
firstname, lastname), account(id, phone, name)];
sObject[] records =
((List<sObject>)results[0]);
if (!records.isEmpty()) {
for (Integer
i = 0; i < records.size(); i++) {
sObject record = records[i];
if
(record.getSObjectType() == Contact.sObjectType) {
contacts.add((Contact)
record);
} else if (record.getSObjectType() ==
Lead.sObjectType){
leads.add((Lead) record);} else if
(record.getSObjectType() == Account.sObjectType) {
accounts.add((Account)
record);
}
}
}

2)
List<List<SObject>> searchList = [FIND 'map*' IN ALL FIELDS
RETURNING Account (id, name),
Contact, Opportunity, Lead];

2010年12月16日木曜日

Extension Contraller

<apex:page standardController="Account"
extensions="ExtOne,ExtTwo">
<apex:outputText value="{!foo}"
/>
</apex:page>


public class ExtOne {
private ApexPages.StandardController
sdController;
public ExtOne(ApexPages.StandardController acon) {sdController
= acon; }
public String getFoo() {
return 'foo-One';
}
}


public class ExtTwo {
private ApexPages.StandardController
sdController;
public ExtTwo(ApexPages.StandardController acon) {sdController
= acon; }
public String getFoo() {
return
'foo-Two';
}
}

2010年12月14日火曜日

Standard List Controller Action

a list controller returns 25 records on the page

<apex:page standardController="Account"
recordSetvar="accounts">
<apex:form>
<apex:dataList var="a"
value="{!accounts}">{!a.name}</apex:dataList>
<apex:panelGrid
columns="4">
<apex:commandLink
action="{!first}">First</apex:commandlink>
<apex:commandLink
action="{!previous}">Previous</apex:commandlink>
<apex:commandLink
action="{!next}">Next</apex:commandlink>
<apex:commandLink
action="{!last}">Last</apex:commandlink>
</apex:panelGrid>
</apex:form>
</apex:page>

Standard Controller Action

<apex:page standardController="Contact">
<apex:form
><apex:commandButton action="{!save}"
value="save"/>
<apex:commandButton action="{!quicksave}"
value="quicksave"/>
<apex:commandButton action="{!edit}"
value="edit"/>
<apex:commandButton action="{!delete}"
value="delete"/>
<apex:commandButton action="{!cancel}"
value="cancel"/>
<apex:commandButton action="{!list}"
value="list"/>
<apex:inputField
value="{!contact.LastName}"/>
</apex:form>
</apex:page>

return (new ApexPages.StandardController(account)).cancel();
return (new ApexPages.StandardController(account)).save();
return (new ApexPages.StandardController(account)).edit();//goto edit page
return (new ApexPages.StandardController(account)).view();//goto detail page

Output Word Excel Pdf

Output Word
<apex:page standardController="Account"
contenttype="application/msword">
<apex:pageBlock>
<apex:pageBlockTable
value="{!account.Contacts}" var="contact">
<apex:column
value="{!contact.Name}"/>
<apex:column
value="{!contact.Phone}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>


Output Excel
<apex:page standardController="Account"
contenttype="application/vnd.ms-excel">
<apex:pageBlock>
<apex:pageBlockTable
value="{!account.Contacts}" var="contact">
<apex:column
value="{!contact.Name}"/>
<apex:column
value="{!contact.Phone}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>


Output PDF
<apex:page standardController="Account"
renderAs="pdf">
<apex:pageBlock>
<apex:pageBlockTable
value="{!account.Contacts}" var="contact">
<apex:column
value="{!contact.Name}"/>
<apex:column
value="{!contact.Phone}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>

Style sheet

<apex:stylesheet value="{!URLFOR($Resource.myStyles, 'newStyles.css')}"
/>

• Theme1—Obsolete Salesforce.com theme
• Theme2—Salesforce.com theme used prior to Spring '10
• PortalDefault—Salesforce.com Customer Portal theme
• Webstore—Salesforce.com AppExchange theme
• Theme3—Current Salesforce.com theme, introduced during Spring '10


http://wiki.developerforce.com/index.php/Using_the_Salesforce_CSS_in_Your_Apps


<apex:page standardStylesheets="false">
<!-- page content here
-->
</apex:page>

action support

<apex:actionSupport event="onmouseover"
rerender="detail">
<apex:param name="cid"
value="{!contact.id}"/>
</apex:actionSupport>

action status

<apex:actionStatus startText="Requesting...">
<apex:facet
name="stop">
<apex:detail
subject="{!$CurrentPage.parameters.cid}"
relatedList="false"
title="false"/>
</apex:facet>
</apex:actionStatus>

New Edit Detail URL

<apex:page >
<apex:form >
<a
href="/{!$ObjectType.TestObj__c}/e">New</a><br/>
<a
href="/003A000000GOkuO/e">Edit</a><br/>
<a
href="/003A000000GOkuO">Detail</a><br/>
</apex:form>
</apex:page>

List All Objects

<apex:page standardController="Account"
recordSetvar="objs">
<apex:dataList var="o"
value="{!objs}">
{!o.name}
</apex:dataList>
</apex:page>

Radio Button

<apex:selectRadio value="{!account.name}">
<apex:selectOption
itemValue="Item1" itemLabel="Item 1"/>
<apex:selectOption
itemValue="Item2" itemLabel="Item
2"/>
</apex:selectRadio>

Input Password

<apex:inputSecret value="{!TestObj__c.password}"/>

Goto View Button

<apex:page >
<apex:form>
<apex:commandButton
action="{!URLFOR($Action.TestObj__c.List, $ObjectType.TestObj__c)}" value="Goto
View"/>
</apex:form>
</apex:page>

2010年11月14日日曜日

カスタマイズオブジェクトを取得

Apex Class:XNShowObjectCtl.cls
public with sharing class XNShowObjectCtl {
 public String objName{get;set;}
 public List<SelectOption> getObjNames(){
  List<SelectOption> options = new List<SelectOption>();  
    Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();
    for (Schema.SObjectType st : gd.values()) {
     Schema.DescribeSObjectResult r = st.getDescribe();
     if(r.isCustom() && r.isQueryable()){
       options.add(new SelectOption(r.getName(), r.getLabel()));
     }
    }
  return options;
 }
}

VF Page:XNShowObject.page

<apex:page controller="XNShowObjectCtl" showHeader="true" sidebar="false" >
 <apex:form >
   <apex:selectList value="{!objName}" size="10" multiselect="false">
       <apex:selectOptions value="{!ObjNames}"/>
   </apex:selectList>
  </apex:form>
</apex:page>

2010年11月9日火曜日

CSS Page

File1:CSS.page

<apex:page cache="true" showHeader="false" contentType="text/css">
body  {
    -x-system-font: none;
    background: #E3E3E3 none repeat scroll 0 0;
    font-size-adjust: none;
    font-stretch: normal;
    font-style: normal;
    font-variant: normal;
    font-weight: normal;
}
body, h1, h2, h3, h4, h5, h6, hr12, hb12  {
    font-family: Arial, Helvetica, sans-serif;
}
</apex:page>



File2:VF_Page

<apex:page controller="CatalogCtl" sidebar="false">
<apex:stylesheet value="{!$Page.CSS}" />


</apex:page>

Send Mail

public with sharing class SendMailCtl {
public List toAddress{get;set;}
public String subject{get;set;}
public String content{get;set;}
public void doSend(){
try{
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setUseSignature(false);
mail.setSaveAsActivity(false);
if (toAddress.size() > 0)mail.setToAddresses(toAddress);
mail.setTargetObjectId(UserInfo.getUserId());
//mail.setWhatId(pObjId);
//mail.setTemplateId(mailTemplate.Id);
mail.setSubject(subject);
mail.setPlainTextBody(content);
mail.setSenderDisplayName('test mail');
Messaging.sendEmailResult[] results = Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
for ( Messaging.sendEmailResult result : results ) {
if ( !result.isSuccess () ) {
Apexpages.Message msg = new Apexpages.Message(ApexPages.Severity.ERROR,'Send mail fail.');
Apexpages.addMessage(msg);
}
}
}
catch(Exception ex){
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.FATAL, 'Send mail fail:' + ex.getMessage()));
}
}
}

Test Class

@isTest
private class ClsTest {
static testMethod void testMethodl() {
System.assert(true);
System.assertEquals('Expected value', 'Actual value');
}
}

2010年10月20日水曜日

多言語対応VF Page

1)通訳有効化
1-1)設定>トランスレーションワークベンチ>翻訳設定>有効化
1-2)「追加」(言語=英語、有効=Check)→「保存」

2)カスタム表示ラベルを追加
2-1)設定>作成>カスタム表示ラベル>「新規カスタム表示ラベル」
2-2)「新規カスタム表示ラベル」(簡単な説明=Language_Text、値=日本語で表示する)→「保存」
2-3)「翻訳」(言語=英語、通訳テキスト=Show English Text.)
2-4)「新規カスタム表示ラベル」(簡単な説明=Language_Label、値=English)→「保存」
2-3)「翻訳」(言語=英語、通訳テキスト=日本語)
名前/簡単な説明/値/通訳(英語)
Language_Label/Language Label/English/日本語
Language_Text/Language Text/日本語で表示する。/Show English Text.

3)クラスを作成LanguageTestCls.cls
public with sharing class LanguageTestCls {
//apex:page's language attriber
public String lng{get;set;}
//class's text
public String showLabel{get;set;}
//vf page's text
public String showText{get{return System.Label.Language_Text;}set;}
//Change language aciton
public void changeLanguage(){
if(lng == 'en')
lng='ja';
else
lng='en';
}
}
4)VF Pageを作成LanguageTestPage.page
<apex:page controller="LanguageTestCls" language="{!lng}">
<h1>
<apex:form >
<apex:commandButton value="{!$Label.Language_Label}" action="{!changeLanguage}"/>
</apex:form>
</h1>
<br/>
<apex:outputtext value="{!showText}"></apex:outputtext>
</apex:page>
5)出来ましたか
http://browser_current_url/apex/LanguageTestPage

2010年9月19日日曜日

カスタム表示ラベル

Apexからの利用方法
System.Label.<ラベル名>

Visualforceからの利用方法
$Label.<ラベル名>

2010年9月12日日曜日

getParameters

if (ApexPages.currentPage().getParameters() == null) {
//;
} else {
String value = ApexPages.currentPage().getParameters().get(paramId);
}

2010年7月13日火曜日

try..catch

try{
insert myObj;
}catch (DmlException e){
System.assertEquals('FIELD_CUSTOM_VALIDATION_EXCEPTION',e.getDmlStatusCode(0));
}

対象データ削除

List delObj= [select id from MyObj__c where createdById = :createdbyId];
if(!delObj.isEmpty()){
delete delObj;
}

2010年3月14日日曜日

Apex Describe Information

// Create a new account as the generic type sObject

sObject s = new Account();

// Verify that the generic sObject is an Account sObject

System.assert(s.getsObjectType() == Account.sObjectType);

// Get the sObject describe result for the Account object

Schema.DescribeSObjectResult r = Account.sObjectType.getDescribe();

// Get the field describe result for the Name field on the Account object

Schema.DescribeFieldResult f = Schema.sObjectType.Account.fields.Name;

// Verify that the field token is the token for the Name field on an Account object

System.assert(f.getSObjectField() == Account.Name);

// Get the field describe result from the token

f = f.getSObjectField().getDescribe();

2010年1月31日日曜日

Select including deleted records

[SELECT count() FROM contact WHERE accountid = a.id ALL ROWS]

Select By parent-child relationships

for( Shopping__c s:[select id,Name,(Select Name From Goods__r limit 1) from Shopping__c where Name=:shop.Name])
{
Goods__c g=s.Goods__r;
goods.Name = g.Name;
}

Select By Foreign Key

shop.Name =
[Select Shopping__r.name From Goods__c where Name=:goods.Name]
.Shopping__r.name;

批処理更新

public void massUpdate() {
for (List <Contact> contacts:[Select FirstName, LastName From Contact]) {
for(Contact c : contacts) {
if (c.FirstName == 'Barbara' &&c.LastName == 'Gordon') {c.LastName = 'Wayne';}
}
update contacts;
}
}

SOQL Functions

●AVG()
SELECT CampaignId, AVG(Amount)
FROM Opportunity
GROUP BY CampaignId
●COUNT()
SELECT COUNT() FROM Account WHERE Name LIKE 'a%'
●COUNT_DISTINCT()
SELECT COUNT_DISTINCT(Company)
FROM Lead
●MIN()
SELECT MIN(CreatedDate), FirstName, LastName
FROM Contact
GROUP BY FirstName, LastName
●MAX()
SELECT Name, MAX(BudgetedCost)
FROM Campaign
GROUP BY Name
●SUM()
SELECT SUM(Amount)
FROM Opportunity
WHERE IsClosed = false AND Probability > 60

2010年1月30日土曜日

SOQL Select from 2 table

① select s.Name,(Select Name From Goods__r) from Shopping__c s
②Select g.Name, Shopping__r.name From Goods__c g


Create a Test Class

@isTest
private class HelloWorldTestClass {
static testMethod void validateHelloWorld() {
Account a = new Account(name='T1 Account');
insert a;
a = [SELECT hello__c FROM account WHERE Id =:a.id];
System.assertEquals('World', a.hello__c);
}
}

Create Trigger

trigger helloWorldAccountTrigger on Account (before insert) {
Account[] accs = Trigger.new;
MyHelloWorld.addHelloWorld(accs);
}

Force.com議事録

今日から、Salesforce.comの研修議事録始まります。