Salesforce の標準機能には、2 つの場所 (住所 1 と住所 2) の間の距離を計算する機能はありません。2 つの場所 (住所 1 と住所 2) の間の距離を計算したい場合、カスタマイズが必要となります。
この記事では、カスタマイズの概要を説明いたします。
【カスタマイズの概要】
(1) 「カスタム住所項目の要件と制限事項」の確認
カスタム住所項目を有効化する前に、要件と制限事項を確認します。
(2) 「カスタム住所項目の有効化」
カスタム住所項目を有効化します。
(3) 「カスタム住所項目の作成」
住所データ型を使用して、標準の住所項目の動作を模倣するカスタム住所項目を 2 つ作成します。
※ この記事では、同じオブジェクトにカスタム住所項目 [住所 1] (API 参照名 : Address1__c) および [住所 2] (API 参照名 : Address2__c) を作成したものと仮定します。
(4) 「カスタム住所項目への地理コードの追加」
Apex クラス等により、マップ API から取得した緯度・経度 (地理コード) をカスタム住所項目に追加します。
※ デフォルトでは、カスタム住所項目に住所を入力しても、当該カスタム住所項目の緯度 (API 参照名: {カスタム住所項目の項目名}__Latitude__s) および経度 (API 参照名: {カスタム住所項目の項目名}__Longitude__s) は空 (null) のため、緯度・経度を別途追加する必要があります。
(5) カスタム数式項目 (戻り値のデータ型: 数値) の作成
「GEOLOCATION 関数」にカスタム住所項目の緯度・経度を渡すと、地理位置情報が返ってきます。
さらに、2 つの場所 (カスタム住所項目の地理位置情報) を「DISTANCE 関数」に渡すと、2 つの場所の間の距離を計算した結果 (数値) が指定した単位 (マイルまたはキロ単位) で返ってきます。
これらの関数を使用した数式の例を以下に示します。
[数式の例] ※ /* から */ はコメント
/* DISTANCE 関数で、場所 ① と場所 ② の間の距離 (単位: km) を返す */
DISTANCE(
/* 場所 ① : GEOLOCATION 関数で、[住所1] 項目 (API 参照名: Address1__c) の地理位置情報を返す */
GEOLOCATION(Address1__Latitude__s, Address1__Longitude__s),
/* 場所 ② : GEOLOCATION 関数で、[住所2] 項目 (API 参照名: Address2__c) の地理位置情報を返す */
GEOLOCATION(Address2__Latitude__s, Address2__Longitude__s),
/* 単位 : km を指定 */
'km'
)
カスタマイズの概要は以上です。
詳細はリンク先の記事をご覧ください。
000385894

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.