Continuing on the second installment of the first blog on how to create and deploy BitBucket in Salesforce, we have arrived again to guide you through the next step of creating Unit class and an LWC component to complete the configuration process.

So, without any delay. Let’s start!

Creating Apex Classes and LWC Components for Deployment

First, we need to Clone the Bitbucket Repository in the local system:

  • Go to your Bitbucket repository created in the previous blog.
  • Click on Bit Bucket Repo1 and then click on Clone.
  • Clone the repo into your local system.

Here we are cloning via Vs Code.

Click on Bit Bucket Repo1 and then click on Clone

Click on Clone in Vs Code. It will redirect you to your vs code. Click on Clone a New Copy.

Click on Clone a New Copy

Then give the path to your repo in local system.

give the path to your repo

Choose the C directory to save the repo in a local system. Then Click on select as a repository destination.

After selecting the folder you will get a pop-up of git, git will authorize your Bit Bucket account.

authorize your Bit Bucket account

Click on Sign In with your browser.

Make sure it should open in the same browser where you created your Bit Bucket account. Click on grant Access and it will authorize your account.

Click on grant Access

It has created a local repository in C directory with same name of repository.

Create Project for deployment:

  • Open your Vs Code.
  • Click Ctrl + shift + P. Then select Create Project with Manifest>Standard.
  • Enter the name of the project I’m entering First Project.
  • Select the C:\bit bucket repo1( we have created in previous step )as a path for project. Then click on Create Project. 
Select the bitbucket path

It has created a sfdx project in system.

Authorize the Dev Org:

  • Now it’s time to authorize the dev sandbox we have created in step 9 of the previous blog.
  • In Vs code click ctrl + shift + P and choose to authorize an org.
  • Click on Sandbox, give them any Dev_org, and click enter.
  • It will redirect you to a new window and ask for the Username and Password.
  • For Username add the production’s Username with the .dev suffix and for the Password enter the same password as the production if you did not change the password.
  • For example, if your production username is abc@force.com then your dev username will be abc@force.com.dev
  • After successful authorization a small pop-up will be shown in the right bottom corner which will show a successful message.

Creating an LWC component and Apex class with its test class:

Create an Apex class:

  • In Vs Code navigate force-app>classes.
  • Right-click on the classes folder and click on Create Apex Class.
  • For name enter firstApexClass and click enter, for path select force-app\main\default\classes.
  • Copy this code in the firstApexClass.cls file.

Create Unit test class for above apex class

  • In Vs Code navigate force-app>classes.
  • Right click on classes folder and click on Create Apex Unit Test Class.
  • For name enter firstApexClassTest click enter, for path select force-app\main\default\classes.
  • Copy this code in firstApexClassTest.cls file.

Create an LWC Component

  • In Vs Code navigate force-app>lwc.
  • Right click on lwc folder and click on Create Lightning Web Component.
  • For name enter firstLwc click enter, for path select force-app\main\default\lwc.
  • Configure firstLwc.html file :
  • Copy this html code into your firstLwc.html file.

Create a Configure firstLwc.js file:

  • Copy this js code into your firstLwc.js file
  • Configure firstLwc.js-meta.xml file:
  • Copy this code in firstLwc.js-meta.xml file.
  • Configure __tests__ folder file:
  • Open your __tests__ folder under firstLwc.
  • Open firstLwc.test.js file and comment out “import { createElement } from ‘lwc’”.
  • It looks like this:

Commented on this line

  • Now deploy components one by one according to their dependency in source org.
  • First of all deploy apex class and its test class then deploy LWC components one by one.
  • After successful deployment open dev org(source org) and add LWC component in Home page by clicking edit page and dragging firstLwc Component from left custom component section.
  • Click on activate. And Refresh the page. Now you will be able to see your component in Home page.

Configure .gitignore file:

  • Find .gitignore file in your FirstProject folder.
  • Open this file and under “# LWC Vs Code autocomplete” comment paste below line:

It Looks like below:

FirstProject folder

Create package.xml file:

  • Right-click on force-app\main\default then click on New file.
  • Enter the file name package.xml
  • Paste the below code on this file.

Configure the Bitbucket pipeline file:

  • This file is responsible for automating the CI/CD process.
  • From File Explorer navigate bitbucket-pipeline file from C:\bit-bucket-repo1 folder.
  • Select the bitbucket-pipeline file & right-click to open with Vs Code. Then paste the below code.

Create Asset folder to upload server.key.enc and server1.key.enc file in project:

  • From file explorer navigate bit-bucket-repo1 folder.
  • Open bit-bucket-repo1 folder and create a new folder give name assets.
create a new folder

Copy server.key.enc and server1.key.enc file from C:\JWT and paste it inside the assets folder.

Wrap Up

That concludes the process of creating Apex classes and LWC Component, deploying each component individually in the source org. In our upcoming blog, we will delve into the intricacies of pushing these changes to the BitBucket repository and deploying them in the production environment.
For a detailed walkthrough of these steps, keep an eye out for our next blog!

Related Articles
Expert Guide On Nominal XIRR Calculation Using LWC in Salesforce

When building financial tools within Salesforce, handling irregular cash flows with precision is a must. Whether you’re developing investment trackers, portfolio performance dashboards, or funding monitors, calculating Nominal XIRR (Extended Internal Rate of Return) becomes essential. In this blog, you’ll learn how to build a Lightning Web Component (LWC) in Salesforce that calculates Nominal XIRR […]

Read More
Beginners Guide to Making Your LWC Component Multilingual

If you’re wondering how to make your LWC component multilingual, you’re already ahead of the curve. Global users expect content in their native language, and Salesforce gives you the tools to deliver exactly that. With Custom Labels and the Translation Workbench, you can easily localize your Lightning Web Components without touching a single line of […]

Read More
Hands-On Guide Building a Drag-and-Drop Form Builder Using Lightning Web Components

Drag-and-drop interfaces are a user experience staple, and when paired with the power of Lightning Web Components (LWC), they unlock dynamic, highly interactive Salesforce components. In this blog post, we’ll walk you through how to build a custom drag-and-drop form builder in LWC. Users can drag form fields like text inputs and dropdowns into a […]

Read More
Please Make Blog Banner How to Create an Agentforce Enabled Scratch Org in Salesforce 100 1

Setting up an Agentforce-enabled scratch org is the most important step for developers who want to experiment with AI features such as Prompt Builder and Einstein GPT. Whether you’re developing the next generation CRM software or experimenting with how generative AI may improve user experience, a scratch org equipped with Agentforce is your playground. Follow […]

Read More
Step-by-Step Guide to Enhance Your LWC Development Workflow with the Logger API

Are you looking to streamline your LWC development workflow but confused about how to do it? Then you are in the right place. The Salesforce Logger API is a powerful tool that helps you monitor, debug, and improve code quality in real time.  This step-by-step guide walks you through how to set it up and […]

Read More
Enhancing Your Salesforce Experience with a Custom Activity Component

In today’s fast-paced business landscape, productivity hinges on streamlined workflows and intuitive interfaces. While Salesforce offers robust activity tracking capabilities, sometimes the standard components fall short of specific organizational needs.  That’s where a Custom Activity Component comes in—designed to tailor your activity management experience, boost user efficiency, and provide deeper insights into customer interactions. In […]

Read More
Our Location worldwide
Indian Flag India
3rd Floor, A-10, Pegasus Tower, Sector 68, Noida, Uttar Pradesh 201301 +91-1203117884
United States of America Flag USA
333 West Brown Deer Road Unit G – 366 Milwaukee WI, USA 53217 +1(262) 310-7818
United Kingdom Flag UK
7 Bell Yard, London, WC2A 2JR +44 20 3239 9428
Canada Canada
HIC Global Solutions INC
43 Lafferty Lane, Richmond Hill, L4C 3N8, CA +1(262) 310-7818