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. 

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.

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

In this detailed guide, we will walk you through the significant yet easy steps to configure Email to Salesforce. Without any further ado, let’s get started! About Email to Salesforce As the term refers, Email to Salesforce is valuable for any organization that businesses use as their Customer Relationship Management (CRM) platform. It helps streamline […]

Read More
Guide on CRUD Operations in Node.js with jsForce

CRM developers typically need to integrate Salesforce with Node.js apps. One well-known library for this purpose is jsForce, which provides a comprehensive set of tools for interacting with Salesforce data and performing CRUD tasks effectively. Let’s dive into the blog, where you will understand the use of jsForce to execute key CRUD tasks within Salesforce, […]

Read More
How to Implement Round Robin Assignments in Salesforce Using Apex

Ensuring a proper workload balance and quick follow-ups from internal or external team members, leads, opportunities, or task distributions is crucial. To achieve this, all you need is a Round Robin assignment. In this step-by-step guide, we will walk you through the process of implementing a round-robin assignment in Salesforce using Apex. Here, we’ve used […]

Read More
Best Salesforce Developments Services Provider

In this step-by-step guide, we will walk you through the significant role of Large Data Volumes in Salesforce, and what strategies or practices you should keep in mind. What is Large Data Volumes? In Salesforce, Large Data Volumes (LDV) refers to managing a huge amount of records available in the platform. LDV usually comes into […]

Read More

Salesforce Apex includes numerous built-in text handling classes, and in addition to them, the Pattern and Matcher classes are good for performing complex string operations. These classes enable us to define and work with regular expressions, which are of particular importance for data validation, searching, and modification. In this technical blog, we will find out […]

Read More

Maintaining security and compliance in Salesforce requires effective user access management. This article will lead you through the process of creating expiration dates for Permission Sets and Permission Set Groups, allowing you to automate access removal while minimizing manual work. Know how this functionality simplifies workflows, guarantees compliance, and improves security procedures. Why Use Expiration […]

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