CRUD from Record Variable
Last updated
Was this helpful?
Last updated
Was this helpful?
The Avonni Dynamic Components provide a set of interactions that allow you to perform CRUD (Create, Read, Update, Delete) operations on Salesforce records directly. These interactions operate on Record Variables that you define within your Dynamic Component.
These interactions are not typically used with components that have built-in data binding and automatic updates (like Data Table, List, Kanban, Map). Those components handle data updates through their data source configurations. Instead, the CRUD interactions are most valuable when:
Working with Individual Records: You need to create, update, or delete a single record based on user actions or other logic outside the context of a repeating list.
Building Custom Forms with the : When creating a bespoke form for creating a new record or editing an existing one. This method gives you complete control over layout and which fields are presented as individual input components.
Combined with "": You want to retrieve a record's data when a component loads, modify it, and then save the changes.
Complex Scenarios: More complex scenarios require fine-grained control over record manipulation.
Create from Record Variable: Creates a new Salesforce record using the data in a Record Variable.
Update from Record Variable: This method modifies an existing Salesforce record, updating it with the data in a Record Variable.
Upsert from Record Variable: Creates or updates a new record.
Delete from Record Variable: Deletes a Salesforce record. Use this with extreme caution!
This approach is common when you are:
Building custom forms to create new records.
Editing a record that is not the main record of the page (e.g., editing a related record loaded into a variable).
Needing a separate "working copy" of record data before saving.
The process is:
a. Define a Record Variable: In the Resources panel, create a Variable resource. Set its Data Type to Record
and specify the Salesforce Object API Name (e.g., Account
, Contact
, My_Custom_Object__c
). Give it a clear API Name (e.g., accountToEdit
, newContactForm
).
b. Populate the Record Variable: You need to get data into this Record Variable. This can happen through:
User Input (for Creates/Updates): Place individual input components (Text Input, Number Input, Picklist, etc.) on your canvas. You can easily do this by dragging fields from the Fields Tab (which will show fields based on your accountToEdit
Record Variable). These input components become automatically bound to the fields of your Record Variable (e.g., {!accountToEdit.Name}
, {!accountToEdit.Industry}
). As the user types or makes selections, your accountToEdit
variable is updated.
"On Load" > "Get Records" (for Updates/Deletes of specific/related records): Use an "On Load" interaction on your component to fetch a specific record (e.g., a related record's details) and store the result directly into your Record Variable.
Other Interactions: This variable could also be populated by a flow ("Execute Flow" action with output mapping) or a "Set Variable Value" action.
c. Trigger the Record Operation: Add an interactive component (usually an Avonni Button) and configure an On Click (or other relevant event) interaction.
d. Choose the CRUD Interaction: In the interaction settings, select the appropriate action type:
Create from Record Variable
Update from Record Variable
Upsert from Record Variable
Delete from Record Variable
e. Select Your Record Variable: In the action's configuration, choose the Record Variable you defined and populated (e.g., {!accountToEdit}
).
f. Select Fields (for Create/Update/Upsert): Specify which fields from the selected Record Variable should be included in the create, update, or upsert operation.
$Component.record
)This approach is used when your Dynamic Component is placed on a Salesforce record page, and you want to view, edit, and save changes to that specific record.
b. Place on Matching Record Page: Add your Dynamic Component to a corresponding record page using the Lightning App Builder (e.g., place the component with Target Object Account
onto an Account record page).
c. Display/Edit Fields using $Component.record
: Fields dragged from the Fields Tab (which now shows fields for your Target Object) onto your canvas will typically be automatically bound to $Component.record.FieldName
(e.g., $Component.record.Name
). Users can view or edit these fields.
d. Trigger the Save Operation: Add an Avonni Button (e.g., labeled "Save Changes") and configure an On Click interaction.
e. Choose the Save Record
Interaction: In the interaction settings, select the Save Record
action type.
This specific interaction is designed to save any modifications made to fields bound to the current page's record context ($Component.record
). It typically doesn't require you to re-select the record variable or fields, as it acts on the established page context.
This example demonstrates using a Record Variable and the "Create from Record Variable" interaction to build a custom form for creating new Lead records.
You want a simple, focused form on an App Page or Home Page to quickly capture new Leads. It should have a specific layout and only the essential fields, rather than the standard "New Lead" button, which might have many fields.
Create a Record Variable for the New Lead:
In your Dynamic Component's Resources panel, create a new Variable.
API Name: newLeadData
Data Type: Record
Object API Name: Select Lead
.
Build the Form Using the Fields Tab:
With the newLeadData
Record Variable selected (or just available in your resources), go to the Component Library (left panel) and select the Fields Tab. You will see fields from the Lead
object.
Drag the following fields onto your canvas to create input components. They will automatically bind to your newLeadData
variable:
FirstName
LastName
(Text Input)
Company
(Text Input)
Email
(Email Input)
LeadSource
(will likely create a Combobox if it's a picklist)
Arrange these input components on the canvas as desired (e.g., within a Card or Columns component for better layout).
Add a "Create Lead" Button
Drag an Avonni Button component onto the canvas below your input fields.
Label: "Create Lead"
Variant: brand
(or your preferred style)
Configure the "Create from Record Variable" Interaction
Select the "Create Lead" Button.
In the Properties Panel, go to the Interactions section.
Add an interaction to the On Click event.
Action Type: Choose Create from Record Variable
.
Record Variable: Select your {!newLeadData}
variable from the resource list.
Fields: Click "Add Field" for each field you want to save from your form (FirstName
, LastName
, Company
, Email
, LeadSource
). This tells Salesforce which fields from your newLeadData
variable to include when creating the new Lead record.
Add Feedback (Optional but Recommended)
Still within the "On Click" interaction of the Button, after the "Create from Record Variable" action, click "Add Action" again.
Action Type: Show Toast
.
Configure Toast:
Title: Success
Message: New Lead created successfully!
Variant: success
When a user fills out the custom form:
The input components (Text Inputs, Combobox) directly update the fields within the newLeadData
Record Variable in real-time (due to the binding created when dragging from the Fields tab).
When the user clicks the "Create Lead" button, the "Create from Record Variable" interaction takes all the data currently in the newLeadData
variable and uses it to create a new Lead record in Salesforce.
The success toast message then appears.
This example clearly shows:
Defining a Record Variable for a new record.
Populating that Record Variable using input fields bound via the Fields Tab.
Using the "Create from Record Variable" interaction to save that data to Salesforce
Record Variables are Essential: These CRUD interactions require Record Variables.
Data Binding for Input: Use data binding to connect Input components to the fields of your Record Variable.
Error Handling: Consider adding error handling (e.g., using the "On Error" event of the "Execute Flow" interaction if you're using a Flow for more complex logic).
Permissions: Users need the appropriate Salesforce permissions (Create, Edit, Delete) on the relevant objects.
Use the Delete Action with caution: Use the delete action carefully.
Avonni Dynamic Components provides a powerful way to interact with Salesforce data using Record Variables and CRUD interactions. These features allow you to build sophisticated data management capabilities without writing code, making it ideal for creating custom forms and updating related records.
a. Select Target Page Object: In your Dynamic Component's Settings (gear icon ⚙️), define the (e.g., Account
). This crucial step tells your component it's operating in the context of that Salesforce object.
"On Load" for Retrieval: Use with "Get Records" to fetch existing record data.