How do you test a Salesforce agent before production?
Use a Salesforce developer or scratch org, then test the platform rules that reject writes: governor limits, validation rules, required fields, and record types. An agent that creates a lead in a unit test will still fail when a validation rule blocks the write.
Start with the official test environment
Salesforce Developer Edition and scratch orgs are free and behave like production. Configure yours with the validation rules, required fields, and record types your real org enforces, or the test proves nothing.
Where agents actually break
The happy path is the easy part. An agent that can do the simple version of the task will still fall over on the cases below, and these are the ones worth building tests around:
- A validation rule that rejects a record the agent thought was complete
- A required field the agent left empty
- A governor limit hit during a batch operation
- A record type or picklist value the agent did not account for
- A duplicate rule that blocks a create the agent expected to succeed
How to test it properly
Give the agent a realistic starting state, let it run the full task end to end, then check the state it left behind rather than the response it returned. Run the same scenario twice to confirm it does not duplicate work or corrupt state on a retry. Then deliberately inject a failure partway through, a rejected write or a rate limit, and confirm the agent recovers instead of charging ahead as if nothing happened.