[salesforce]APEXでランダム文字列生成

By |5月 19, 2010|salesforce, |


こんなかんじ。

[php]
public string getRandomString(Integer LengthRequired){
String CharList = ‘abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_’;
String Res = ”;
integer position;
for(Integer i = 0; i <= LengthRequired; i++) {
position = Integer.valueof(String.valueof(Math.roundToLong(CharList.length()*Math.random()))) -1;
Res += CharList.substring(position,position+1);
}
return Res;
}
[/php]