您位於此處:
若發生 Apex 例外,會如何?
若發生例外,程式碼執行會停止。在例外之前處理的任何 DML 作業會回復且不會認可至資料庫。例外會記錄在除錯記錄中。針對未處理的例外,也就是程式碼未找出的例外,Salesforce 會傳送一封包含例外資訊的電子郵件。一般使用者會在 Salesforce 使用者介面中看到一則錯誤訊息。
若發生例外,程式碼執行會停止。在例外之前處理的任何 DML 作業會回復且不會認可至資料庫。例外會記錄在除錯記錄中。針對未處理的例外,也就是程式碼未找出的例外,Salesforce 會傳送一封包含例外資訊的電子郵件。一般使用者會在 Salesforce 使用者介面中看到一則錯誤訊息。
| 提供版本:Salesforce Classic (並非所有組織皆適用) 和 Lightning Experience |
| 提供版本:Performance、Unlimited、Developer、Enterprise 及 Database.com Edition |
| 需要的使用者權限 | |
|---|---|
| 若要存取 Apex 例外電子郵件設定頁面 | 「檢視設定」權限 |
| 若要撰寫 Apex 程式碼 | Author Apex |
| 使用 Tooling API 的時機 | 已啟用 API |
出現未處理的 Apex 例外時,系統會傳送電子郵件,其中包含 Apex 堆疊追蹤、例外訊息、客戶的組織及使用者識別碼、組織及使用者名稱,以及「我的網域」名稱。報告中不會傳回任何其他資料。預設會將未處理例外電子郵件傳送至在失敗類別或觸發上的「上次修改者」欄位中指定的開發人員。此外,您也可以將電子郵件傳送至 Salesforce 組織的使用者以及任意電子郵件地址。這些電子郵件收件者也可以收到程序或流程錯誤電子郵件。若要設定這些電子郵件通知,請進入「設定」,在「快速尋找」方塊中輸入 Apex 例外電子郵件,然後選取「Apex 例外電子郵件」。接著,輸入的電子郵件地址會套用至客戶組織中所有受管理的封裝。您也可以使用 Tooling API 物件 ApexEmailNotification 來設定 Apex 例外電子郵件。
如需有關未處理例外狀況電子郵件的詳細資訊,請參閱未處理例外狀況電子郵件
如果一般使用者在使用標準使用者介面時遇到 Apex 程式碼中發生例外,會出現一則錯誤訊息。該錯誤訊息包括與下文所示通知類似的文字。

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.