Apple や Android OS のディープリンクと連携する決済処理システムなど、広く利用されている連携機能では、特定のフォルダ構造やコンテンツを連携ページ上に構築することで、サイトの所有権を確認する必要があります。これらは通常、/.well-known/ フォルダパスから始まり、設定データを含む JSON ファイルが個別に配置されます。この用途で一般的に参照されるファイルには、assetlinks.json や apple-site-association があります。
Salesforce では、任意のサイトに対して /.well-known パスを直接設定することはできません。さらに、Salesforce はこれらのエンドポイントの一部に独自の設定を事前に設定しています。ただし、URL リライターを使用することで、適切なパスに存在するように見えるページをサービス側に提示しつつ、実際には必要なコンテンツを含む Visualforce ページを返すことができます。
なお、この方法ではリダイレクトが発生するため、リダイレクトに対応していないサービスや、HTTP 200 OK ステータスコードの返却を必須とするサービスでは利用できません。
まず 必要な情報を含む Visualforce ページを作成し、URL リライターが容易に識別できるよう、説明的かつ一意の名前を付けます。必ず contentType を適切に指定してください。この例では、ページ名を「myAssetLink」としています。
<apex:page standardStylesheets="false" sidebar="false" showHeader="false" applyHtmlTag="false" applyBodyTag="false" contentType="text/json"> <!-- Specify your JSON content here --> </apex:page>
Mobile Publisher、Experience Cloud、または同様の Lightning ソリューションで使用する場合は、[Lightning Experience、Experience Builder サイト、モバイルアプリで使用可能] のチェックボックスが有効になっていることを確認してください。
各ファイルにはそれぞれ専用の Visualforce ページが必要となるため、必要に応じて複数のページを作成してください。また、連携内容の要件によっては、組織内の異なるサイト向けに、同一ファイルの複数コピーが必要になる場合があります。
次に URL リライターを作成します。サードパーティ連携を複数のサイトで行う場合は、複数の URL リライターが必要になる可能性があります。以下に、前述の例を継続して使用した Android Asset Links 設定の実装例を示します。
global with sharing class AssetLinkRedirect implements Site.UrlRewriter{
//Variables to represent the user-friendly URLs for the new page
String ASSETLINK_PAGE = '/apex/myAssetLink';
global PageReference mapRequestUrl(PageReference myFriendlyUrl){
String url = myFriendlyUrl.getUrl();
system.debug('=====URL======'+url);
if(url != null && url.endsWith('assetlinks.json')){
system.debug('=====Modified Android Asset Links======');
return new PageReference(ASSETLINK_PAGE);
}
return null;
}
global List<PageReference> generateUrlFor(List<PageReference> mySalesforceUrls){
return null;
}
}
この Apex クラスでは Site.UrlRewriter インターフェースを実装し、mapRequestUrl メソッドを使用して、渡された URL が 目的の署名と一致するかどうかを確認します。一致した場合は、先ほど作成した JSON コンテンツをホストするカスタム Visualforce ページへの新しい PageReference を返します。
Apex クラスを作成したら対象サイトに移動し、そのクラスを URL リライターとして設定します。
Salesforce サイトの場合:
Experience Cloud サイトの場合:
最後に、ブラウザで設定したページに直接アクセスし、実装が正しく動作していることを確認します。
000396664

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.