URL クラス
名前空間
使用方法
1// Get a file uploaded through Chatter.
2ContentDocument doc = [SELECT Id FROM ContentDocument
3 WHERE Title = 'myfile'];
4// Create a link to the file.
5String fullFileURL = URL.getSalesforceBaseUrl().toExternalForm() +
6 '/' + doc.id;
7system.debug(fullFileURL);例
1// Create a new account called Acme that we will create a link for later.
2Account myAccount = new Account(Name='Acme');
3insert myAccount;
4
5// Get the base URL.
6String sfdcBaseURL = URL.getSalesforceBaseUrl().toExternalForm();
7System.debug('Base URL: ' + sfdcBaseURL );
8
9// Get the URL for the current request.
10String currentRequestURL = URL.getCurrentRequestUrl().toExternalForm();
11System.debug('Current request URL: ' + currentRequestURL);
12
13// Create the account URL from the base URL.
14String accountURL = URL.getSalesforceBaseUrl().toExternalForm() +
15 '/' + myAccount.Id;
16System.debug('URL of a particular account: ' + accountURL);
17
18// Get some parts of the base URL.
19System.debug('Host: ' + URL.getSalesforceBaseUrl().getHost());
20System.debug('Protocol: ' + URL.getSalesforceBaseUrl().getProtocol());
21
22// Get the query string of the current request.
23System.debug('Query: ' + URL.getCurrentRequestUrl().getQuery());URL のコンストラクタ
URL のコンストラクタは次のとおりです。
Url(spec)
署名
public Url(String spec)
パラメータ
- spec
- 型: String
- URL として解析する文字列。
Url(context, spec)
署名
public Url(Url context, String spec)
使用方法
1<scheme>://<authority><path>?<query>#<fragment>このコンストラクタの引数についての詳細は、Java のそれぞれの URL(java.net.URL, java.lang.String) コンストラクタを参照してください。
URL のメソッド
URL のメソッドは次のとおりです。
getCurrentRequestUrl()
署名
public static System.URL getCurrentRequestUrl()
戻り値
型: System.URL
使用方法
要求全体の URL の例は、https://yourInstance.salesforce.com/apex/myVfPage.apexp です。
getDefaultPort()
署名
public Integer getDefaultPort()
戻り値
型: Integer
使用方法
URL の URL スキームまたはストリームプロトコルハンドラにデフォルトのポート番号が定義されていない場合、-1 を返します。
getFileFieldURL(entityId, fieldName)
署名
public static String getFileFieldURL(String entityId, String fieldName)
パラメータ
戻り値
型: String
使用方法
例:
例
1String fileURL =
2 URL.getFileFieldURL(
3 '087000000000123' ,
4 'AttachmentBody');getOrgDomainUrl()
署名
public static System.Url getOrgDomainUrl()
戻り値
型: System.URL
getOrgDomainUrl() は、コンテキストに関係なく、組織の同じドメインを返します。このメソッドを使用して、Lightning Experience と Salesforce Classic の両方で機能するか、組織への API コールを実行するときのドメインとして機能する、レコードの URL へのリンクを構築します。
使用方法
getOrgDomainUrl() を使用して、API コードで Salesforce の REST API と SOAP API を操作します。選択リスト値セットとカスタム項目の作成やカスタマイズなどで、ユーザインターフェース API コールのエンドポイントを取得します。
getOrgDomainUrl() は、Apex コードが実行されている組織のドメイン URL にのみアクセスできます。
このメソッドで取得したドメイン URL を使用して Salesforce API を操作するのに、組織の RemoteSiteSetting は不要です。リモートサイトの設定をスキップするには、組織で [私のドメイン] が有効になっている必要があります。
例
この例では、Salesforce REST API を使用して、組織の制限値が取得されます。詳細は、『REST API 開発者ガイド』の「制限」を参照してください。
getSalesforceBaseUrl()
署名
public static System.URL getSalesforceBaseUrl()
戻り値
型: System.URL
現在の接続のホスト名を返します (例: https://MyDomainName.my.salesforce.com、https://MyDomainName.lightning.force.com。または [私のドメイン] が無効な組織の場合は https://yourInstance.salesforce.com、https://yourInstance.lightning.force.com)。
getUserInfo()
署名
public String getUserInfo()
戻り値
型: String
使用方法
UserInfo 部分が存在しない場合は null を返します。
sameFile(URLToCompare)
署名
public Boolean sameFile(System.URL URLToCompare)
パラメータ
- URLToCompare
- 型: System.URL
使用方法
URI とフラグメントコンポーネントの構文についての詳細は、「RFC3986」を参照してください。