Implementation
Key Features
Complex Object Construction
Create JavaScript objects that match the structure of Apex wrapper classes:Property Name Mapping
JavaScript object properties must match Apex class property names:Dynamic List Population
Build arrays dynamically before sending to Apex:Parameter Passing
Pass the complex object as a named parameter:Properties
| Property | Type | Description |
|---|---|---|
stringValue | String | String value to send to Apex |
numberValue | Number | Integer value to send to Apex |
listItemValue | Number | Number of items to include in the list |
message | String | Response message from Apex |
error | Object | Error object if the call fails |
Parameters
JavaScript Object Structure
Apex Method Parameters
| Parameter | Type | Description |
|---|---|---|
wrapper | CustomWrapper | Custom wrapper object containing complex data |
Apex Wrapper Class Requirements
- AuraEnabled annotation: All properties must be annotated
- Public access: Properties must be public
- Get/Set methods: Use
{ get; set; }syntax - Sharing rules: Use
with sharingfor security
Type Mapping
Primitive Types
| JavaScript | Apex |
|---|---|
| String | String |
| Number | Integer, Decimal, Double |
| Boolean | Boolean |
| null | null |
Complex Types
| JavaScript | Apex |
|---|---|
| Object | Custom Apex class, sObject |
| Array | List |
| Date | Date, DateTime |
Advanced Examples
Nested Objects
sObject Parameters
List of sObjects
Error Handling
Handle errors for complex parameter validation:When to Use
Use complex parameters when:- Sending multiple related values
- Working with nested data structures
- Passing sObjects or custom types
- Building objects dynamically
- Sending data from forms with multiple fields
Best Practices
- Match property names exactly: JavaScript object properties must match Apex class properties (case-sensitive)
- Use wrapper classes: Create dedicated Apex classes for complex parameters
- Validate before sending: Check data integrity in JavaScript
- Document structure: Clearly document the expected object shape
- Handle type conversion: Be aware of JavaScript to Apex type mapping
- Use meaningful names: Name properties clearly for maintainability
- Test edge cases: Test with null values, empty arrays, etc.
Common Pitfalls
- Case sensitivity:
someString≠somestring - Type mismatches: Sending String when Apex expects Integer
- Missing @AuraEnabled: Apex properties must be annotated
- Null handling: JavaScript undefined becomes null in Apex
- Date formats: Use ISO format for dates
