Auth の例外
Auth 名前空間には、いくつかの例外クラスが含まれています。
すべての例外クラスは、エラーメッセージや例外型を返す組込みメソッドをサポートしています。「Exception クラスおよび組み込み例外」を参照してください。
Auth 名前空間には、次の例外があります。
例
次の例では、AuthProviderPluginException を使用して、カスタム認証プロバイダ実装内のすべてのメソッドにカスタムエラーメッセージをスローしています。エンドユーザに特定のメッセージを表示する場合、この例外を使用してエラーメッセージをパラメータとして渡します。別の例外を使用した場合、ユーザには標準の Salesforce エラーメッセージが表示されます。
1global override Auth.OAuthRefreshResult refresh(Map<string,string> authProviderConfiguration,String refreshToken){
2 HttpRequest req = new HttpRequest();
3 String accessToken = null;
4 String error = null;
5 try {
6
7 // DEVELOPER TODO: Make a refresh token flow using refreshToken passed
8 // in as an argument to get the new access token
9 // accessToken = ...
10 } catch (System.CalloutException e) {
11 error = e.getMessage();
12 }
13 catch(Exception e) {
14 error = e.getMessage();
15 throw new Auth.AuthProviderPluginException('My custom error');
16 }
17
18 return new Auth.OAuthRefreshResult(accessToken,refreshToken, error);
19 }次の例では、ユーザが高保証セッションを使用せずにアカウントの作成を試みた場合に Auth.VerificationException を使用して検証をトリガします。
1trigger testTrigger on Account (before insert) {
2 Map<String, String> sessionMap = auth.SessionManagement.getCurrentSession();
3 if(!sessionMap.get('SessionSecurityLevel').equals('HIGH_ASSURANCE')) {
4 throw new Auth.VerificationException(
5 Auth.VerificationPolicy.HIGH_ASSURANCE, 'Insert Account');
6 }
7}