Salesforce String ReplaceAll

String a = ‘文字32十は3十52年, 1十2際十5文字列は十桁です’;

String b = a.replaceAll(‘([0-9])(十)([0-9])’, ‘$1$3’);
String b1 = b.replaceAll(‘([0-9])(十)’, ‘$10’);
String c = b1.replaceAll(‘(十)([0-9])’, ‘1$2’);
String d = c.replaceAll(‘十’,’10’);
System.debug(d);

 

Result:
———————————————
文字320は352年, 12際15文字列は10桁です

Get Record Type By De

//To get the RecordTypeInfo of ApprovedOutBoundMail__c
public static Schema.RecordTypeInfo getRecTypeInfo( String strRecTypeName ){

Schema.DescribeSObjectResult DescPack = Schema.SObjectType.ApprovedOutBoundMail__c;
Map<String,Schema.RecordTypeInfo> appRcName= DescPack.getRecordTypeInfosByName();
Schema.RecordTypeInfo rcType= appRcName.get(strRecTypeName);
return rcType;

}

Salesforce 配列初期化 簡略書き方

http://blog.jeffdouglas.com/2011/01/06/fun-with-salesforce-collections/

省略初期化方法
set -> list :
Set setStrings = new Set{‘hello’,’world’};
List listStrings = new List(setStrings);

// create a new set with 3 elements
Set s = new Set{‘Jon’, ‘Quinton’, ‘Reid’};
// adds an element IF not already present
s.add(‘Sandeep’);
// adds an element IF not already present
s.add(‘Sandeep’);
// return the number of elements
System.debug(‘=== number of elements: ‘ + s.size());
// removes the element if present
s.remove(‘Reid’);
// return the number of elements
System.debug(‘=== number of elements: ‘ + s.size());
// returns true if the set contains the specified element
System.debug(‘=== set contains element Jon: ‘ + s.contains(‘Jon’));
// output all elements in the set
for (String str : s)
// outputs an element
System.debug(‘=== element : ‘ + str);
// makes a duplicate of the set
Set s1 = s.clone();
// displays the contents of the set
System.debug(‘=== contents of s1: ‘ + s1);
// removes all elements
s1.clear();
// returns true if the set has zero elements
System.debug(‘=== is the s1 set empty? ‘ + s1.isEmpty());

List s = new List{‘Jon’, ‘Quinton’, ‘Reid’};
// adds an element
s.add(‘Sandeep’);
// adds an element
s.add(‘Sandeep’);
// return the number of elements
System.debug(‘=== number of elements: ‘ + s.size());
// displays the first element
System.debug(‘=== first element: ‘ + s.get(0));
// removes the first element
s.remove(0);
// return the number of elements
System.debug(‘=== number of elements: ‘ + s.size());
// makes a duplicate of the set
List s1 = s.clone();
// displays the contents of the set
System.debug(‘=== contents of s1: ‘ + s1);
// replace the last instance of ‘Sandeep’ with ‘Pat’
s1.set(3,’Pat’); // displays the contents of the set
System.debug(‘=== contents of s1: ‘ + s1);
// sorts the items in ascending (primitave only)
s1.sort();
// displays the contents of the set
System.debug(‘=== sorted contents of s1: ‘ + s1);
// removes all elements
s.clear();
// returns true if the set has zero elements
System.debug(‘=== is the list empty? ‘ + s.isEmpty());

Map m = new Map{5 => ‘Jon’, 6 => ‘Quinton’, 1 => ‘Reid’};
// displays all keys
System.debug(‘=== all keys in the map: ‘ + m.keySet());
// displays all values
System.debug(‘=== all values in the map (as a List): ‘ + m.values());
// does the key exist?
System.debug(‘=== does key 6 exist?: ‘ + m.containsKey(6));
// fetches the value for the key
System.debug(‘=== value for key 6: ‘ + m.get(6));
// adds a new key/value pair
m.put(3,’Dave’);
// returns the number of elements
System.debug(‘=== size after adding Dave: ‘ + m.size());
// removes an element
m.remove(5);
System.debug(‘=== size after removing Jon: ‘ + m.size());
// clones the map
Map m1 = m.clone();
System.debug(‘=== cloned m1: ‘ + m1);
// removes all elements
m.clear();
// returns true if zero elements
System.debug(‘=== is m empty? ‘ + m.isEmpty());

Jquery勉強サイト[よく使えるJquery Plugin]

http://www.skuare.net/test/jQuery_5.html

http://www.skuare.net/test/jTableHover.html

MessageBox:

http://jquerymsgbox.ibrahimkalyoncu.com/

download:   jquery.msgBox(v1.0)

Option Confirmable Values Description
content any string the message text. as default:’Message’
title any string the title of the message as default:’Warning’
type ‘alert’,’confirm’,’error’,’info’,’prompt’ type of the message will be shown. as default:’alert’
autoClose boolean values true for activating auto-closing, else false. as default:false
timeOut milisecons auto-close timeout. as default:content.length * 70
showButtons boolean values true for displayin buttons on message, else false. as default:true
buttons array format:[{value:”Button1″},{value:”Button2″}]. as default:[{value:”Ok”}]
success callback a callback function that passed the value of the button has been clicked.
beforeShow callback a callback before message shown.
afterShow callback a callback after message shown.
beforeClose callback a callback before message closed.
afterClose callback a callback after message closed.
opacity a value 1 between 0 the css property of the back panel of message box. as default:0.1

Salesforce小技巧和备注

  1. WFの項目自動更新された項目に対して、項目入力規則はnot fire
  2. ProcessInstanceにて、[SELECT Id, (SELECT Id, StepStatus, Comments FROM Steps),TargetObjectId FROM ProcessInstance]で、該当データLockedされるどうか判断可能
  3. 数値VFに書式化:
    <apex:outputText value="{0,number,#,###}"> 
    <apex:param value="{!detailInfo.HokenKingaku__c/1000}" />  
    </apex:outputText>
  4. M-D関係構築
    M-D1-DD1-DDD1 3階層まで構築可能です
    M-D-Mの場合、DのオブジェクトはMになることができません
  5. スケジュールクラス定義(秒まで定義する)
    DateTime nowTime = DateTime.now().addSeconds(10);
    // 起動CRONを設定する
    String timeStr = nowTime.format('yyyyMMddHHmmss');
    String yy = timeStr.substring(0,4);
    String mm = timeStr.substring(4,6);
    String dd = timeStr.substring(6,8);
    String hh = timeStr.substring(8,10);
    String ms = timeStr.substring(10,12);
    String ss = timeStr.substring(12,14);
    String sch = ss + ' ' +
    			 ms + ' ' +
    			 hh + ' ' +
    			 dd + ' ' +
    			 mm + ' ' +
    			 ' ? ' + yy;
    
    ApexClassXXX m = new ApexClassXXX();
    String jobName = DateTime.now().format('yyyyMMddHHmmssSSS') + '|' + String.valueof(Crypto.getRandomLong());
    String jobId = system.schedule(jobName, sch, m);
  6. 日付書式
    《apex:outputText》
    <apex:outputText value="{0,date,dd/MM/yyyy}">
    <apex:param value="{!DATEVALUE(m_dtimSomeVar)}"/>
    </apex:outputText>
  7. 数値書式
    《apex:outputText value="{0,number,#,###}"》
    《apex:param value="{!detailInfo.HokenKingaku__c/1000}" /》
    《/apex:outputText》
  8. 根据Salesforce Id 判断Sobject类型
    参照文档:
    Returns the three-character prefix code for the object. Record IDs are prefixed with three-character codes that specify the type of the object (for example, accounts have a prefix of 001 and opportunities have a prefix of 006).

        Schema.DescribeSObjectResult R = Account.SObjectType.getDescribe();
        String a = R.getKeyPrefix();
        String sid = 'a00d00000039F47';
        String b = sid.substring(0,3);
        // the data is Account Type Data Type 
        if (a == b) {
           System.debug('it is account data');   
        } else {
    
        }
  9. Visualforce to Excel
    <apex:page standardController="Account" contenttype="application/vnd.ms-excel">
  10. ApexでFormat処理を行う
    public static String paddingLeftZero(Decimal n, Integer len) {
    Integer nlen = (Math.floor(Math.log10(Double.valueOf(n))).intValue() + 1);
    if(nlen >= len) return n.format();
    String s = '';
    for(Integer i=0, l=len-nlen; i<l; i++) {
    s += '0';
    }
    return s + n;
    }
    

deploy metafile by ant

部署做好的metafile到服务器有两种常用的方式,
利用IDE部署到服务器->  deploy to server
还有就是利用ant进行部署,下面记录一下,利用ant进行部署的几个关键点
准备工作:
  1. ANT(1.6以上) + J2SE(1.5以上)  ←ant运行环境
  2. SFDC关联的部署插件 这个需要login到SFDC的环境里面,在设定-〉开发-〉tool里面下载
  3. 把2种下载的文件,解压,把ant-salesforce.jar文件copy到ant的lib下面
  4. 编写build.xml文件

文件结构 ant/bin/ant
build.xml
build.properties
src/package.xml
class/*****
objects/******

  • 下面是一个例子
# build.properties
#

# Specify the login credentials for the desired Salesforce organization
sf.username = xxxxxxxxx
sf.password = xxxxx
#sf.pkgName = <Insert comma separated package names to be retrieved>
#sf.zipFile = <Insert path of the zipfile to be retrieved>
#sf.metadataType = <Insert metadata type name for which listMetadata or bulkRetrieve operations are to be performed>

# Use 'https://login.salesforce.com' for production or developer edition (the default if not specified).
# Use 'https://test.salesforce.com for sandbox.
sf.serverurl = https://test.salesforce.com

# If your network requires an HTTP proxy, see http://ant.apache.org/manual/proxy.html for configuration.
#
build.xml

<project name="Sample usage of Salesforce Ant tasks" default="test" basedir="." xmlns:sf="antlib:com.salesforce">

    <property file="build.properties"/>
    <property environment="env"/>

    <!-- Deploy the unpackaged set of metadata retrieved with retrieveUnpackaged -->
    <target name="deployUnpackaged">
      <sf:deploy username="${sf.username}" password="${sf.password}" serverurl="${sf.serverurl}" deployRoot="src"/>
    </target>

    <!-- Shows check only; never actually saves to the server -->
    <target name="deployCodeCheckOnly">
      <sf:deploy username="${sf.username}" password="${sf.password}" serverurl="${sf.serverurl}" deployRoot="src" checkOnly="true"/>
    </target>

</project>
准备要部署的metafile文件和package.xml
编写package.xml
把这次要部署的文件列表写入到package.xml
例子:
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <members>xxx1</members>
        <members>xxx2</members>
        <name>ApexClass</name>
    </types>
    <types>
        <members>xxx1</members>
        <members>xxx2</members>
        <name>ApexPage</name>
    </types>
    <types>
        <members>xxx1</members>
        <members>xxx2</members>
        <name>ApexTrigger</name>
    </types>
    <types>
        <members>xxx1</members>
        <members>xxx2</members>
        <name>CustomApplication</name>
    </types>
    <types>
        <members>xxx1</members>
        <members>xxx2</members>
        <name>CustomLabels</name>
    </types>
    <types>
        <members>xxx1</members>
        <members>xxx2</members>
        <name>CustomObject</name>
    </types>
    <types>
        <members>xxx1</members>
        <members>xxx2</members>
        <name>CustomObjectTranslation</name>
    </types>
    <types>
        <members>xxx1</members>
        <members>xxx2</members>
        <name>Layout</name>
    </types>

    <types>
        <members>xxx1</members>
        <members>xxx2</members>
        <name>ReportType</name>
    </types>

    <types>
        <members>xxx1</members>
        <members>xxx2</members>
        <name>Profile</name>
    </types>

    <types>
        <members>xxx1</members>
        <members>xxx2</members>
        <name>StaticResource</name>
    </types>
    <types>
        <members>xxx1</members>
        <members>xxx2</members>
        <name>Translations</name>
    </types>
    <types>
        <members>xxx1</members>
        <members>xxx2</members>
        <name>Workflow</name>
    </types>
    <version>23.0</version>

</Package>

进行部署检证
ant deployCodeCheckOnly

进行实际部署
ant deployUnpackaged