Get Started with the Models API | Models API 入门(练习操作步骤)

《Get Started with the Models API | Models API 入门》的分步练习操作指南。...

📅 2026/10/2 ✍️ ponybai 🏷️ agentforce, salesforce, ai

本文是《Get Started with the Models API | Models API 入门》的练习操作步骤。阅读原文请见:Get Started with the Models API | Models API 入门。

1. Sign Up for a Trial Org

  1. Click Create Playground (auto-attached to your Trailhead account).
  2. Note the expiration date and click Launch.
  3. In Setup, search for and select Users, check your name, click Reset Password(s), then set a new password via the email link.

2. Enable Einstein and Disable Caching

  1. Click the gear icon and select Setup.
  2. Search for and select Einstein Setup, and ensure the Turn on Einstein toggle is On.
  3. Search for and select Session Settings, and under Caching, deselect "Enable secure and persistent browser caching to improve performance."

3. Install the CLI and VS Code Extensions

  1. Install [Salesforce CLI](https://developer.salesforce.com/tools/salesforcecli) and confirm it's up to date.
  2. Install Visual Studio Code, then install the Salesforce Extension Pack.

4. Create and Connect a Project

  1. In VS Code, open the Command Palette (Ctrl+Shift+P / Cmd+Shift+P).
  2. Select SFDX: Create Project, accept defaults, name it ModelsAPILWC, and select a folder.
  3. Open the Command Palette and select SFDX: Authorize an Org, accept defaults, and log in with your AI Playground credentials (click Allow).

5. Create Models API Apex Classes

  1. Right-click force-app/main/classes and select SFDX: Create Apex Class → name it DashboardController; remove default code and paste the provided code.
  2. Create another class HousingData, paste the provided code, and save.
  3. Right-click the classes folder and select SFDX: Deploy This Source to Org.

6. Build a Models API Lightning Web Component

  1. Open the Command Palette and select SFDX: Create Lightning Web Component → name modelsAPIDashboard.
  2. Paste the provided code into modelsAPIDashboard.html, modelsAPIDashboard.css, modelsAPIDashboard.js, and modelsAPIDashboard.js-meta.xml.

7. Deploy to Your AI Playground

  1. Right-click the modelsAPIDashboard folder and select SFDX: Deploy This Source to Org.
  2. Verify the Deployed Source message in the Output tab.

8. Edit Page in Lightning App Builder

  1. Open the Command Palette and select SFDX: Open Default Org.
  2. Click the gear icon → Setup, search for and select Home, and set Advanced Seller Home to Inactive.
  3. Search for and select Lightning App Builder, then New → Home Page → Next.
  4. Label Home_Page_Default, Next, select a layout, then Done.
  5. Drag the modelsAPIDashboard component to the top of the Page Canvas.
  6. Click Save, then Activate → Org Default → Assign as Org Default → Save twice.
  7. Open the Sales app to view the new Home page.