Apexのデータ型変換まとめ【Salesforce】

By | August 1, 2021

Idのデータ型変換

Id → String

String convertedStr = String.valurOf(id);

String → Id

Id convertedId = Id.valueOf(str);

Integerのデータ型変換

Integer → String

String convertedStr = String.valurOf(int);

String → Integer

Integer convertedInt = Integer.valueOf(str)

Integer → Decimal

Decimal convertedDec = decimal.valueOf(int);

Decimal → Integer

Integer convertedInt = Integer.valueOf(decimal)

Decimalのデータ型変換

Decimal → String

String convertedStr = String.valurOf(decimal);

String → Decimal

Decimal convertedDec = decimal.valueOf(str);

Decimal → Integer

Integer convertedInt = Integer.valueOf(decimal)

Integer → Decimal

Decimal convertedDec = decimal.valueOf(int);

Dateのデータ型変換

Date → String

String convertedStr = String.valurOf(date);

String → Date

Date convertedDate = Date.valueOf(str);

Date → DateTime

Datetime dt = datetime.newInstance(date.year(), date.month(),date.day());

DateTime → Date

Date date = date.newinstance(dt.year(), dt.month(), dt.day());

DateTimeのデータ型変換

DateTime → String

String convertedStr = String.valurOf(dt);

String → DateTime

Datetime convertedDt = DateTime.valueOf(str);

DateTime → Date

Date date = date.newinstance(dt.year(), dt.month(), dt.day());

Date → DateTime

Datetime dt = datetime.newInstance(date.year(), date.month(),date.day());