本文是《Agentforce Vibes — AI 驱动的代码排查与重构搭档》的练习操作步骤。阅读原文请见:Agentforce Vibes — AI 驱动的代码排查与重构搭档。
1. Reproduce the Bug
- Return to your playground and open the App Launcher, then select Agentforce Adventure Tools.
- In the Quick Dice Roller, click a die button (for example, 1 D20).
- Notice the toast says the roll is saved, but the sum shows as
undefined.
2. Confirm Your Connection
- In the Agentforce Vibes tab, click Start a New Task.
- Ask:
What is the username of the Salesforce Org I'm currently connected to? - Press enter/return (approve commands if prompted).
- Confirm the correct username appears.
3. Retrieve the Source
- Open the Files Explorer (Ctrl+Shift+E / Cmd+Shift+E).
- Ensure the
manifestfolder withpackage.xmlexists (create both if missing). - Replace
manifest/package.xmlwith the provided contents and save. - Click the Agentforce icon and Start a New Task.
- Ask:
Please retrieve the source from my default org based on the manifest file. - Confirm
DiceRollService(inforce-app/main/default/classes) anddiceRoller(inforce-app/main/default/lwc) are retrieved.
4. Format the Code
- In the search bar, enter
DiceRollService.clsand select it. - Click the Agentforce icon and Start a New Task.
- Ask:
Please format the DiceRollService class using prettier-plugin-apex. If the plugin is not installed, install it using npm and then use the npx prettier --write command. - Press enter/return (approve/allow commands as prompted).
- Review the suggestions, ignore the Problems tab, and save with Ctrl+S / Cmd+S.
5. Fix the Bug
- Click Start a New Task and paste the provided bug-fix prompt.
- Press enter/return and review what Agentforce returns.
- If the fix is correct, accept the change and click Save / Run Command as prompted.
6. Deploy and Test
- Click Start a New Task and ask:
Deploy the DiceRollService.cls class to my default org. - Approve commands as prompted.
- Refresh the Agentforce Adventure Tools page.
- Add a modifier and roll the dice a few times; confirm totals and sums now display correctly.
- (Optional) Open the Dice Rolls tab → All Rolls List View to see recent rolls.
7. Improve the Code (Remove @track)
- Open the
diceRoller.jsfile (searchdiceRoller.js). - Click Start a New Task and paste the provided @track-removal prompt.
- Press enter/return and review the suggestions.
- Click Save and confirm the variable is renamed and getter/setter created.
- Click Start a New Task and ask:
Deploy the diceRoller LWC to my default org. - Return to the app and retest the Quick Dice Roller.