本文是《Get Started with the Models API | Models API 入门》的练习操作步骤。阅读原文请见:Get Started with the Models API | Models API 入门。
1. Sign Up for a Trial Org
- Click Create Playground (auto-attached to your Trailhead account).
- Note the expiration date and click Launch.
- 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
- Click the gear icon and select Setup.
- Search for and select Einstein Setup, and ensure the Turn on Einstein toggle is On.
- 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
- Install [Salesforce CLI](https://developer.salesforce.com/tools/salesforcecli) and confirm it's up to date.
- Install Visual Studio Code, then install the Salesforce Extension Pack.
4. Create and Connect a Project
- In VS Code, open the Command Palette (Ctrl+Shift+P / Cmd+Shift+P).
- Select SFDX: Create Project, accept defaults, name it
ModelsAPILWC, and select a folder. - 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
- Right-click
force-app/main/classesand select SFDX: Create Apex Class → name itDashboardController; remove default code and paste the provided code. - Create another class
HousingData, paste the provided code, and save. - Right-click the classes folder and select SFDX: Deploy This Source to Org.
6. Build a Models API Lightning Web Component
- Open the Command Palette and select SFDX: Create Lightning Web Component → name
modelsAPIDashboard. - Paste the provided code into
modelsAPIDashboard.html,modelsAPIDashboard.css,modelsAPIDashboard.js, andmodelsAPIDashboard.js-meta.xml.
7. Deploy to Your AI Playground
- Right-click the
modelsAPIDashboardfolder and select SFDX: Deploy This Source to Org. - Verify the Deployed Source message in the Output tab.
8. Edit Page in Lightning App Builder
- Open the Command Palette and select SFDX: Open Default Org.
- Click the gear icon → Setup, search for and select Home, and set Advanced Seller Home to Inactive.
- Search for and select Lightning App Builder, then New → Home Page → Next.
- Label
Home_Page_Default, Next, select a layout, then Done. - Drag the modelsAPIDashboard component to the top of the Page Canvas.
- Click Save, then Activate → Org Default → Assign as Org Default → Save twice.
- Open the Sales app to view the new Home page.