Implementation
Key Features
Passing Parameters
Pass parameters as an object with property names matching Apex parameter names:Parameter Object Syntax
Separate Input Handling
Handle input changes separately from search execution:User-Controlled Execution
The search only executes when the user clicks the Search button:Properties
| Property | Type | Description |
|---|---|---|
searchKey | String | The current search input value |
contacts | Array | List of contacts matching the search |
error | Object | Error object if the call fails |
Parameters
Apex Method Parameters
| Parameter | Type | Description |
|---|---|---|
searchKey | String | Search term to filter contacts by name |
Error Handling
Use try/catch to handle errors gracefully:Multiple Parameters Example
For methods with multiple parameters:Parameter Types
Supported parameter types:| JavaScript Type | Apex Type |
|---|---|
| String | String |
| Number | Integer, Decimal, Double |
| Boolean | Boolean |
| Object | Custom Apex class, sObject |
| Array | List |
| null/undefined | null |
When to Use
Use imperative calls with parameters when:- Search functionality needs a submit button
- You want to validate input before calling Apex
- You need to combine multiple inputs into one call
- You want to avoid calling Apex on every keystroke
- You need to perform operations before/after the Apex call
Comparison with Wire and Parameters
| Feature | Imperative | Wire with Params |
|---|---|---|
| Execution | On button click | Automatic on param change |
| Control | Full control | Automatic |
| Debouncing | Not needed | Required |
| Validation | Before call | Not possible |
| User action | Explicit (button) | Implicit (typing) |
Best Practices
- Validate input: Check parameters before calling Apex
- Handle empty input: Decide behavior for empty search
- Clear previous results: Reset state on new search
- Show feedback: Indicate search in progress
- Handle no results: Show appropriate message
