> For the complete documentation index, see [llms.txt](https://learning.contextqa.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://learning.contextqa.com/packaged-application-testing/salesforce-testing/hybrid-ui-api-testing.md).

# Hybrid UI and API Testing

Build Salesforce tests with API setup, Lightning UI actions, record readback, data isolation, and evidence for business outcomes.

> **Documentation owner:** [Deep Barot](https://contextqa.com/academy/) · **Last updated:** November 12, 2026

## Quick answer

Use APIs to prepare and read back Salesforce records, and use the UI to validate the user journey and role-specific experience. Capture identifiers at runtime so both layers inspect the same records. Check field values, relationships, and downstream state rather than treating a successful HTTP response or save notification as the complete outcome.

## Key takeaways

* Capture record IDs and reuse them across UI and API steps.
* Run permission checks as the relevant role rather than an unrestricted integration user.
* Use bounded waits and clean up only run-owned synthetic records.

## Before you start

Choose an approved sandbox, a synthetic data prefix, and two identities: the business user and the least-privilege API user needed for the test. Use your org’s supported API version and authentication configuration. Store credentials in the approved protected configuration; never embed them in test descriptions, URLs, screenshots, or exported reports.

Confirm object API names, required fields, record types, restricted picklists, validation rules, and permissions with the Salesforce owner. An API-only test executed as an administrator does not validate a salesperson’s access.

## Example: create records through the API, verify an opportunity in Lightning

1. Create a [ContextQA API test](https://learning.contextqa.com/enterprise-application-testing/api-testing/creating-api-tests.md) using the authorized Salesforce connection and your test environment.
2. Create a synthetic account. Assert the response indicates success and capture its record identifier as a runtime variable.
3. Create a contact and opportunity linked to that account. Capture their identifiers; assert the returned relationship values through a separate read.
4. Open a browser case with the salesperson’s reusable login prerequisite. Locate the opportunity using the captured identifier or unique run-owned name.
5. Verify account and contact relationships, visible amount, currency, stage, and fields expected for that role.
6. Change the opportunity stage through the UI and save. Wait for the expected state with a bounded timeout; refresh or reopen the record.
7. Read the same opportunity through the authorized API. Compare the exact stored stage, amount, and relationship IDs with the expected values.
8. If a Flow creates a task or downstream request, verify that record and correlation ID too. A successful opportunity update is not evidence of downstream completion.
9. Attach the sanitized response assertions and UI run evidence to the requirement. Clean up only the records created by this run, in dependency order.

Use [API chaining](https://learning.contextqa.com/enterprise-application-testing/api-testing/api-chaining.md) and [environment data management](https://learning.contextqa.com/enterprise-application-testing/web-testing/environment-data-management.md) for runtime values and isolation. In your implementation, define the expected business values before generating the test.

## Choose the layer for each assertion

| Question                                             | Best evidence                                               |
| ---------------------------------------------------- | ----------------------------------------------------------- |
| Can the salesperson see and edit the intended field? | UI action under that role and permission-aware readback     |
| Did the relationship save correctly?                 | Exact record-ID comparison after the write                  |
| Did the validation rule reject invalid data?         | Expected error plus unchanged stored state                  |
| Did the downstream system accept the event?          | Correlated destination result, not only an outbound request |
| Did a retry create duplicates?                       | Record count and stable business key after controlled retry |
| Did an asynchronous Flow finish?                     | Bounded polling for its documented final state              |

## How to validate migrated data

1. Record source totals, mapping version, external keys, expected exclusions, and the target snapshot.
2. Reconcile counts by business category; totals alone can hide misplaced records.
3. Compare required values, parent-child relationships, currency, dates, and duplicate handling for deterministic samples and high-risk records.
4. Run representative UI journeys on migrated records under each relevant role.
5. Exercise an incremental rerun to check idempotency. Keep mismatches and untested categories in the release decision.

## Troubleshooting

| Symptom                                        | Check next                                                                    |
| ---------------------------------------------- | ----------------------------------------------------------------------------- |
| API succeeds but UI cannot find the record     | User sharing, org/environment, record type, and the captured ID               |
| UI save passes but readback differs            | Flow updates, rounding, field-level access, and asynchronous processing       |
| Parallel runs intermittently fail              | Shared users, unique keys, record locks, org limits, and cleanup collisions   |
| Expected rejection passes as a generic failure | Assert the specific error and unchanged state; distinguish transport failures |

## Frequently asked questions

### Does HTTP success prove the business workflow passed?

No. Verify the stored values and dependent records. For asynchronous operations, wait for the documented terminal state or report the run as blocked or failed according to your policy.

### Can I mix a privileged setup identity with a restricted UI user?

Yes, for controlled data preparation. Label the identity for every assertion and run authorization checks as the restricted user. Privileged setup must not hide missing business-user permissions.

### What screenshots should I retain?

Capture the selected test configuration without secrets, the critical UI action, the persisted result, and any expected rejection. Link each image to the case and run; redact customer data before sharing it. See [execution video and screenshots](https://learning.contextqa.com/enterprise-application-testing/execution/video-and-screenshots.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://learning.contextqa.com/packaged-application-testing/salesforce-testing/hybrid-ui-api-testing.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
