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
Step-by-Step Guide on Adding Opportunity Team Members to Slack Channel

Salesforce allows you to improve communication by effortlessly connecting Opportunity Team Members to Slack channels. This step-by-step blog will show you how to enable Opportunity Teams, configure Slack integrations, and automate the process with Salesforce Flow. Real-time Slack notifications may help you streamline communication, increase productivity, and keep your sales team on the same page. […]

Read More
How to Use Transform Element in Salesforce Flow

Salesforce introduced the transform element in their winter ‘24 release. This feature simplifies data processing in flows by eliminating the need for loops and assignment elements. With the Transform Element, you can seamlessly map source data to target data, making your flows more efficient and easier to maintain. Transform element is available for screen flows, […]

Read More
How to Use TypeScript in Salesforce Lightning Web Components (LWC)

TypeScript is a programming language developed by Microsoft; used for enhancing JavaScript by adding different static types. With the help of TypeScript, developers can easily find errors during the development process before the execution. It also makes the code more readable and maintainable. With the successful integration of Salesforce Lightning Web Components (LWC), TypeScript improves […]

Read More
Expert Guide on Seamless Integration of Salesforce and QuickBooks Online

Integrating Salesforce with QuickBooks Online can significantly streamline your business operations, improving data accuracy and efficiency. QB Sync Made Easy offers a seamless solution to synchronize customer and financial data between the two platforms. This expert QuickBooks Online, on the other hand, is a leading accounting tool specifically developed for small and medium-sized businesses that […]

Read More
A Complete Guide to Salesforce CPQ Contract Amendment and Renewal

Salesforce CPQ software offers robust features for managing pricing, product configurations, and quotations. The capacity to effectively modify and renew contracts is essential for businesses managing intricate agreements and long-term partnerships. In this guide, we’ll walk you through the details of contract amendment and renewal processes in Salesforce CPQ. About Salesforce CPQ Contract Amendments Modifications […]

Read More
Step by Step Guide to Configure Email to Salesforce 1 1

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
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