Create Apex Class & LWC Component in Salesforce from Agentforce Vibe

Salesforce has Agentforce agents, which assist users on the Salesforce platform, and we also have a Service agent that helps customers on the community site, among other services.

But what if a developer needs help while writing code, creating Apex classes, or building flows within Salesforce? For Salesforce developers, enabling Agentforce Vibe helps them build various solutions.

Using Agentforce Vibes, the developer asks, “Write an Apex class to calculate total order amount.” Vibe quickly gives the code, explains how it works, and even suggests improvements. This helps developers save time and write better code more efficiently.

In this article, we will learn how to create an Apex class & LWC component in Salesforce using Agentforce Vibe.

Create an Apex Class & an LWC Component in Salesforce from Agentforce Vibe

Below, I will explain how to create an Apex class and an LWC component in Salesforce from Agentforce Vibe to extend your agent’s functionality and connect custom logic with the Agentforce platform.

Let’s take an example: you want to create a data table to display Account records on the Account record page. We can achieve this by creating an Apex class to retrieve Account data and an LWC component to display it on the page in a dynamic table format.

Now, instead of creating files and writing code manually, we can use Agentforce Vibe to automatically generate the Apex class and LWC component with just a few prompts.

In the image below, you can see we have enabled the MCP server, which helps the Agentforce system connect and communicate with the Salesforce Atlas Reasoning Engine to process AI requests and responses.

We then provided the prompt to Agentforce Vibe to generate an account data table component and automatically deploy it to the Account record page for quick testing and use.

Use Agentforce Vibe in Salesforce

Next, you can see that the agent has automatically written the required code and is prompting to create the file.

This happens because the auto-approval feature for the agent is currently disabled, meaning it needs your confirmation before creating or modifying files.

In Agentforce Vibe, agents have advanced capabilities to generate, edit, and create files directly based on your prompts, making the development process faster and more interactive.

This functionality is not available in Agentforce for Developers, where users must manually create and manage files after the code is generated.

Here, the agent has created an Apex class to retrieve account information from the Salesforce org, allowing the component to fetch and display account data directly from the database dynamically.

How to use Agentforce Vibe in Salesforce

After generating the Apex class and creating the file, the agent prompts you to create the meta.xml file for the Apex class.

This file is important because it defines the class’s metadata, including its API version and visibility, which enables it to be accessed by Lightning components, Flows, or other Salesforce tools.

Agentforce for Developer in Salesforce

After that, it creates the HTML file to define the user interface (UI) of the component. This file controls how the data fetched by the Apex class is displayed on the screen, such as tables, buttons, or text layouts that users see on the account record page.

Similarly, the agent will create the JavaScript file, meta.xml file, and other required component files.

Each time, it will ask for confirmation before saving the file. If you want to review or modify the generated code, you can make changes directly in the editor and then click the Save button to finalize it.

Use Agentforce for Developers in Salesforce

Once the Apex class and LWC component are created, Agentforce Vibe will display a “Run Command” button.

When you click on it, the Agent executes the generated code and deploys the component directly to your Salesforce org, allowing you to see the output live on the account record page without needing any manual deployment steps.

Deploy LWC Component using Agentforce Vibe

In the terminal, you can see that the component is being deployed to Salesforce, and the system has also generated a unique Deploy ID.

This ID helps you track and verify the deployment status within your Salesforce org, ensuring that the component has been successfully uploaded and activated.

Create Apex & LWC in Salesforce from Agentforce Vibe

Now, as you navigate to the account record page, you need to add the newly created LWC component to the page layout using the Lightning App Builder.

This allows you to display the component’s data and functionality directly on the Account record page, making it visible and accessible to end users.

To add the LWC component to the record page, open any account record, then click the gear icon and select Edit Page. This will open the Lightning Page Builder, where you can drag and drop your newly created LWC component onto the page layout.

As you can see below, the data table component has been successfully added to the account record page, displaying the related Account information directly within the page.

This allows users to view and interact with the data in real time without navigating away from the record.

Create DataTable Using Agentforce Vibe in Salesforce

In this way, we can create Apex classes and LWC components in Salesforce directly from Agentforce Vibe.

Conclusion

I hope you have got an idea about how to create an Apex class & LWC component in Salesforce using Agentforce Vibe. In this article, I have explained how the Agentforce vibe generates the code, creates files, and deploys to the Salesforce org.

You may like to read:

Salesforce AgentForce Live Webinar

Agentforce in Salesforce

DOWNLOAD FREE AGENTFORCE EBOOK

Start with AgentForce in Salesforce. Create your first agent and deploy to your Salesforce Org.

Salesforce flows complete guide

FREE SALESFORCE FLOW EBOOK

Learn how to work with flows in Salesforce with 5 different real time examples.