SalesforceとAmazon S3を連携させてみた

SalesforceとAmazon S3を連携させてみた:


やりたいこと

Salesforceで扱うデータを耐久性のあるAWSのS3に保管したい。


参考にしたページ


用意したもの

本記事は以下の環境で記載する。

  • Salesforce Developer Edition Winter 2018 (Lightning Experience)
  • ForceCode for Visual Studio Code


作業手順


Force.com for Amazon Web Servicesのインストール

"Installing Force for Amazon Web Services"にアクセスし、Install Toolkit from AppExchangeの [1] をクリックしてSalesforceにToolkitをインストール。


image.png



リモートサイトの設定

Salesforceにログインし、「設定」→「セキュリティ」→「リモートサイトの設定」と進み、「新規リモートサイト」をクリックする。

なお、リモートサイトのURLはリージョンも指定する形で入力する。

例えば、アジアパシフィック(東京)ならhttps://s3.ap-northeast-1.amazonaws.comとなる。



image.png



Force.com for Amazon Web Services の設定

「アプリケーションランチャー」→「AWS Credentials」と進み、「新規」でAWSの資格情報を登録する。


image.png


項目
Credential Name 任意の名前
Key IAMユーザのアクセスキー
Secret IAMユーザのシークレットアクセスキー


カスタムオブジェクトの編集

「オブジェクトマネージャ」→「AWS S3 Object」→「ボタン、リンク、およびアクション」→「新規 (の▼) 」→「編集」



image.png




image.png


「Salesforce Classicの上書き」を以下のように設定。

  • 「Visualforceページ」を選択
  • 「news3object」を設定


image.png



ForceCode for Visual Studio Codeの設定

以下の記事を参考に設定します。
Visual Studio Code で Salesforce 開発環境を作る


apexコードの変更

AWSCredentialNameの変更とリージョン情報の追記を行う。

classes

  • AWS_ExplorerCon.cls

    • 3行目
3行目
private String AWSCredentialName = '設定したCredential Name; //Modify this string variable to be the name of the AWS Credential record that contains the proper AWS keys and secret 
  • AWS_S3_ExampleController.cls

    • 41行目
    • 473行目
41行目
private String AWSCredentialName = '任意の名前'; //Modify this string variable to be the name of the AWS Credential record that contains the proper AWS keys and secret 
473行目
String url = 'http://'+bucketToList+'.s3-ap-northeast-1.amazonaws.com/'+filename+'?AWSAccessKeyId='+as3.key+'&Expires='+Lexpires+'&Signature='+signed; 
  • S3.cls

    • 178行目
    • 1407行目
178行目
public String endpoint_x = 'https://s3-ap-northeast-1.amazonaws.com/soap'; 
1407行目
req.setEndpoint('https://s3-ap-northeast-1.amazonaws.com/soap'); 
  • S3FormController.cls

    • 4行目
4行目
private String AWSCredentialName = '設定したCredential Name'; //Modify this string variable to be the name of the AWS Credential record that contains the proper AWS keys and secret 
pages

  • news3object2.page

    • 6行目
6行目
action="https://s3-ap-northeast-1.amazonaws.com/{!AWS_S3_Object__c.Bucket_Name__c}" 
  • s3Preview.page

    • 3行目
3行目
<script>window.location.href="https://s3-ap-northeast-1.amazonaws.com/{!AWS_S3_Object__c.Bucket_Name__c}/{!AWS_S3_Object__c.File_Name__c}";</script> 
カスタムオブジェクト

  • Preview Link
    image.png

数式オプション
HYPERLINK('https://s3-ap-northeast-1.amazonaws.com/'& Bucket_Name__c &'/'& File_Name__c ,  
'https://s3-ap-northeast-1.amazonaws.com/' & Bucket_Name__c &'/'& File_Name__c ) 
以上です。


参考リンク

コメント

このブログの人気の投稿

投稿時間:2021-06-17 05:05:34 RSSフィード2021-06-17 05:00 分まとめ(1274件)

投稿時間:2021-06-20 02:06:12 RSSフィード2021-06-20 02:00 分まとめ(3871件)

投稿時間:2020-12-01 09:41:49 RSSフィード2020-12-01 09:00 分まとめ(69件)