---
schema_version: "1"
id: 62dc6dfde1dd69fbedcc4dacff3ce6687d812c23c5cbfbe870037214d7e48589
title: 結構基本概念
collection: architect
version: next
locale: zh-tw
portal_url: https://docs.salesforce.com/architect/next/zh-tw/fundamentals/guides/architecture-basics.md
canonical_url: https://staging.architect.salesforce.com/docs/architect/zh-tw/fundamentals/guide/architecture-basics.html
source_site: staging.architect.salesforce.com
content_type: documentation
content_hash: 5e51ae3a1e02f933f6d2ca8d484dd9355328df6249cdfe681eec2faa45d2a002
products:
  - 基本概念
  - Architect Site Content Repo
updated_at: 2022-08-01T00:00:00Z
---
## 簡介

Salesforce Customer 360 Platform 為每個個別的 Salesforce 租戶例項 (也稱為「org」) 提供強大的 [多租戶中繼資料驅動結構](/docs/architect/zh-tw/fundamentals/guide/platform-multitenant-architecture)。此結構基本文件提供 Salesforce Platform 基礎結構在其中為平台上建立之解決方案架構建立關鍵考量事項的區域概觀。

在 Salesforce Platform 上設計結構時,需要瞭解三個重要區域:

- [交易](/docs/architect/zh-tw/fundamentals/guide/architecture-basics#交易)
- [中繼資料與資料](/docs/architect/zh-tw/fundamentals/guide/architecture-basics#中繼資料與資料)
- [平台 API](/docs/architect/zh-tw/fundamentals/guide/architecture-basics#平台-api)

## 交易

在 Salesforce Platform 上,可透過程式碼執行和/或資料庫作業例項化交易。在 Salesforce 上建立結構的基本能力是瞭解平台如何定義和控制租戶的交易。為了維護所有租戶的資源,Salesforce 會對每個租戶強制執行限制,根據每個交易和每個組織計算。

在交易層級,Salesforce 會設定 [管理員與執行限制](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_gov_limits.htm),以確保程式碼執行與資料庫交易的個別例項不會獨占共用運算資源。在組織範圍層級,Salesforce 會根據 [版本與功能類型](https://help.salesforce.com/s/articleView?id=sf.overview_limits_general.htm&type=5)設定限制。組織範圍限制也包含組織中所有交易的 API 用量累計計算,這些交易受限於 [API 限制](https://developer.salesforce.com/docs/atlas.en-us.salesforce_app_limits_cheatsheet.meta/salesforce_app_limits_cheatsheet/salesforce_app_limits_platform_api.htm)。

讓我們進一步瞭解 Salesforce Platform 上交易的兩個重要部分:執行內容和資料庫操作。

### 執行內容

Salesforce 會根據 [執行內容](https://trailhead.salesforce.com/content/learn/modules/apex_basics_dotnet/execution_context)的概念計算交易限制。請務必瞭解,針對 Salesforce 應用程式,這不僅限於單一 Salesforce 組織內的自訂程式碼執行。執行內容以平台執行階段引擎為基礎,以及特定租戶其執行階段引擎可用的所有程式碼。這表示租戶組織內定義的自訂程式碼、與該組織一起安裝的封裝程式碼,以及 Salesforce Platform 服務中包含的程式碼,皆可例項化交易。平台會區分不同類型的 Apex 程式碼,並根據這些區別計算管理員限制。

如需有關 [Apex 交易限制](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_gov_limits.htm)的詳細資訊,請參閱 Apex 開發人員指南。

### 資料庫操作

當交易涉及資料庫操作時,內建的執行[順序](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_order_of_execution.htm)會規定您組織組態和程式碼的不同部分會如何運作。瞭解如何在 Salesforce 應用程式中正確使用執行順序的關鍵,就是瞭解此行為為您的 Salesforce 應用程式提供的強大資料完整性。

<a href="/view/MCOOL7W3TDDVFZZGSTXP7SLSI6NI" target="_blank">
    <image style="width:100%;border:1px solid #e5e5e5;margin-top:1rem;margin-bottom:1rem" src="https://architect.salesforce.com/ns-assets/legacy/salesforce-order-of-execution-diagram.png" alt="Salesforce Order of Execution Diagram">
</a>

平台會以[觸發內容變數](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_context_variables.htm)的形式,顯示資料庫作業狀態的內容變數。請務必瞭解,這些觸發內容變數描述 Salesforce 組織中所有資料庫交易的執行階段狀態,無論是否已在該組織中定義自訂 Apex 觸發。它們適用於陳述性工具,例如 Salesforce 流程。

在 Salesforce 中,在執行順序中描述的觸發行為成功完成 _後_,系統不會認可資料 (也無法完成資料交易)。這表示資料交易期間在內容發生*之前*或內容發生*之後*的任何致命錯誤或不符資格行為,都會導致平台回復交易中的所有資料作業。記錄資料的要求變更不會認可至資料庫,且不會執行後認可邏輯。(Apex 確實公開了 [資料庫方法](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_transaction_control.htm),以允許更精確地控制儲存點和回復行為。)

Salesforce 結構中要避免的主要反模式是嘗試縮短或取代平台內建的執行行為順序。

如需進一步瞭解這些內建資料完整性行為背後的邏輯,請參閱 [內部與外部:Salesforce Engineering 部落格上的交易](https://engineering.salesforce.com/inside-and-out-transactions-b9535faa5924)。

## 中繼資料與資料

當選擇您在 Salesforce 組織內自訂及擴充的方式時,請務必瞭解哪些資料會視為資料,以及從 Salesforce Platform 的觀點來看哪些中繼資料會視為中繼資料。如需深入瞭解此資料/中繼資料區別背後的基礎結構,請參閱 [平台多租戶結構](/docs/architect/zh-tw/fundamentals/guide/platform-multitenant-architecture#平台資料層)基本概念文件。

此區分會影響您應用程式的開發生命週期中的許多層面,例如:是否將成品複製到[Sandbox 開發環境中](https://help.salesforce.com/s/articleView?id=sf.create_test_instance.htm&type=5)、如何移轉至其他環境,以及是否可以成為 [封裝](https://developer.salesforce.com/docs/atlas.en-us.packagingGuide.meta/packagingGuide/sharing_apps.htm)的一部分。

下表提供與應用程式生命週期重要部分相關的資料與中繼資料效能快速比較:

<table>
    <tbody>
        <tr>
            <th scope="colgroup" colspan="1">行為</th>
            <th scope="colgroup" colspan="1">資料</th>
            <th scope="colgroup" colspan="1">中繼資料</th>
        </tr>
        <tr>
            <td>從生產環境複製到 Sandbox 環境</td>
            <td>否*</td>
            <td>是</td>
        </tr>
        <tr>
            <td>依中繼資料 API 移轉</td>
            <td>否</td>
            <td>是**</td>
        </tr>
        <tr>
            <td>依資料載入移轉</td>
            <td>是</td>
            <td>否</td>
        </tr>
        <tr>
            <td>可包含在封裝中</td>
            <td>否</td>
            <td>是**</td>
        </tr>
        <tr>
            <td>計入資料儲存限制</td>
            <td>是</td>
            <td>否</td>
        </tr>
        <tr>
         <td colspan="3">*完整複製和部分複製 Sandbox 允許從生產組織複製資料。<br/>**某些中繼資料類型無法與中繼資料 API 和/或封裝搭配使用。您可以在「<a href=https://developer.salesforce.com/docs/metadata-coverage>中繼資料涵蓋範圍報告」中</a>找到例外狀況。</td>
        </tr>
    </tbody>
</table>

有時候,此差異相當明顯。例如,Salesforce 組織中的個別記錄是資料。組織中的各種 [sObject](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_SObjects.htm) 是中繼資料。

對於組織組態功能而言,區分可能較為複雜。重要範例為「[自訂設定](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_customsettings.htm)」與「[自訂中繼資料類型](https://help.salesforce.com/s/articleView?id=sf.custommetadatatypes_about.htm&type=5)」。這些功能皆可讓您設定組織中的資訊,讓資訊在執行階段可供輕鬆使用,並以與資料庫記錄類似的方式進行操作和管理。兩個功能都旨在允許在程式碼和自動化中寬鬆地配對高度彈性的設計模式。然而,「自訂設定」會儲存在組織中作為資料,而「自訂中繼資料類型」會儲存為中繼資料。

您可以查看內容是否出現在「[中繼資料涵蓋範圍報告」中](https://developer.salesforce.com/docs/metadata-coverage),以判斷內容是否為中繼資料。此報告也會告訴您關於特定中繼資料類型的關鍵開發和部署行為。

## 平台 API

有許多 [Salesforce Platform API](https://help.salesforce.com/s/articleView?id=sf.integrate_what_is_api.htm&type=5)。Salesforce Platform API 支援不同的資料格式和通訊協定、各種作業類型和時間。某些 API 允許您與 Salesforce 組織中的資料互動,而其他 API 支援與指定組織中的中繼資料的互動。有些 API 是專門建立以處理 [大量交易](https://developer.salesforce.com/docs/atlas.en-us.api_asynch.meta/api_asynch/asynch_api_intro.htm),有些則不是。Salesforce 會在每個版本中更新 _所有_ Salesforce Platform API 的版本號碼。

有效應用程式結構的關鍵部分是確保應用程式開發人員針對指定的使用個案[使用正確的 API](https://help.salesforce.com/s/articleView?id=sf.integrate_what_is_api.htm&type=5) (和 API 版本)。您必須考慮 Salesforce 組織的內建 [API 限制](https://developer.salesforce.com/docs/atlas.en-us.salesforce_app_limits_cheatsheet.meta/salesforce_app_limits_cheatsheet/salesforce_app_limits_platform_api.htm),其中許多限制是由版本和功能啟用所決定。Salesforce Platform API 支援 [與舊版相容](https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_support_policy.htm)的使用方式,這表示在發行新 API 版本時,具有特定版本的實作應以穩定性和一致性執行。如果您想要從新 API 版本納入新的或變更的功能,您可能需要先重新產生應用程式,再升級對新 API 版本的參照。

許多不同的 Salesforce Platform API,以及 Salesforce API 版本的速度,會對使用 Salesforce API 的任何應用程式生命週期增加顯著的複雜性。您必須規劃在應用程式中定期評估 Salesforce Platform API 參照,並排定計畫 API 維護週期的優先順序,以確保應用程式以可預測且正確的方式執行。
