※この記事は英語版を翻訳しており、内容は後日更新される可能性があります。最新の内容は英語版を参照してください。表示言語は画面右下の言語名から切り替えられます。
Salesforce でのファイルの添付時に何らかの処理を実行したい場合、 Apex トリガーを活用できます。
例:
このようなシナリオでは、メモまたは添付ファイルオブジェクトのトリガーが必要です。
[レコードの [添付ファイル] 関連リストにアップロードしたファイルは、添付ファイルとしてではなく、Salesforce Files としてアップロードされます。] 機能 が無効かつ Classic UI の [メモ&添付ファイル] 関連リストからファイルをアップロードする場合の [Attachment] または [Note] オブジェクトが作成されます。
上記機能が有効または Lightinng Experience UI におけるファイル添付時には、ContentDocument、ContentDocumentLink、ContentVersion オブジェクトが作成されます。
Apex トリガーを作成するには、次のステップに従います。
開発者コンソール で [File] をクリックします。
[New] | [Apex Trigger] の順にクリックします。
名前を付け、ドロップダウンから要件に応じた sObject を選択します。
このトリガーは、VSCode や Agentforce Vibes を使用して作成/記述することもできます。
サンプルコード:
trigger SetTitleToAttachment on Attachment (after insert) {
String Title;
Id pId;
for(Attachment att: Trigger.new){
Title=att.Name; pId=att.ParentId;
}
List<Case> c=[select Id , Title__c from Case where Id=:pId]; //assuming one record is fetched.
c[0].Title__c=Title;
update c[0];
}
ファイルが添付ファイルではなく Salesforce Files としてアップロードされる
Classic と Lightning における ContentDocument と ContentDocumentLink のトリガー動作
000385957

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.