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 b