0% found this document useful (0 votes)
6 views

SFDX Devteam

devops sfdx

Uploaded by

suresh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

SFDX Devteam

devops sfdx

Uploaded by

suresh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Prerequisites:

Check in your pc Git installed or not by following command.

C:\Users\a879239.CORP>git --version

git version 2.43.0.windows.1

C:\Users\a879239.CORP>

Now open Vs code and try to connect GITHUB from VSCODE.

We have two possible ways to connect GITHUB 1. CLI 2. GUI.

Go to source code and click on Initialize Repository. Just like below.

Above step is ON GUI.


Now second way is CLI.

Open New Terminal

Once installed all the plugins and salesforce CLI git then open Terminal and provide below command.

sf –version

next perform below command to initialize git.

PS C:\SIT_VSCODE\SIT> sf --version

@salesforce/cli/2.21.8 win32-x64 node-v20.10.0

PS C:\SIT_VSCODE\SIT> git init

Initialized empty Git repository in C:/SIT_VSCODE/SIT/.git/

PS C:\SIT_VSCODE\SIT>

And then add all the changes by giving below command.

PS C:\SIT_VSCODE\SIT> git add *

Then commit a message ( Bugnumber/ Story number )

PS C:\SIT_VSCODE\SIT> git commit -m "Bug/Story Number"

As of now above all changes will be on local environment now we have to

we have to connect Visual Studio Code to a specific GitHub branch, you can follow these general
steps:

1. Clone the Repository:


 Open Visual Studio Code.

 Use the Clone Repository option by clicking on the "Source Control" icon in the
Activity Bar on the side or by using the Ctrl+Shift+P (Cmd+Shift+P ) shortcut and
typing "Clone Repository."

 Enter the GitHub repository URL and choose a local directory for cloning.

2. Open the Repository:

 Once the cloning is complete, open the cloned repository in Visual Studio Code using
the File > Open... menu or by typing code. in the terminal from the repository
directory.

3. Check Out the Desired Branch:


 Open the Source Control view by clicking on the "Source Control" icon in the Activity
Bar.

 Click on the branch name at the bottom of the window to open the branch
dropdown.

 Choose the branch you want to switch to.

4. Create a New Branch (Optional):

 If the branch you want to connect to is not present locally, you can create a new
branch and set it to track the remote branch.

bashCopy code

git checkout -b new-branch-name origin/branch-name

Replace new-branch-name with the name of the new branch and branch-name with the name of
the branch you want to track.

5. Pull Changes (Optional):

 If you want to ensure that your local branch is up to date with the remote branch,
you can pull the changes.

bashCopy code

git pull origin branch-name

Replace branch-name with the name of the branch.

Now, your Visual Studio Code is connected to the desired GitHub branch.

You can work on your code, commit changes, and push to the specific branch as needed.

The Source Control view in Visual Studio Code allows you to manage your Git branches and commit
changes easily.

To clone or copy the complete Salesforce sandbox metadata to a GitHub branch through Visual
Studio Code, you'll need to follow these general steps:

1. Set Up a Salesforce Project:

 Create a new Salesforce project using Salesforce CLI (SFDX) if you haven't already:

bashCopy code

sfdx force:project:create -n YourProjectName

Change YourProjectName to a name of your choice.

2. Authorize Salesforce Org:

 Authenticate and authorize your Salesforce sandbox org:

bashCopy code
sfdx force:auth:web:login -a YourSandboxAlias -r https://test.salesforce.com

Replace YourSandboxAlias with the desired alias for your sandbox.

3. Retrieve Metadata:

 Retrieve the complete metadata from your sandbox:

bashCopy code

sfdx force:source:retrieve -u YourSandboxAlias -x path/to/package.xml

Create a package.xml file to specify the metadata components you want to retrieve.

4. Initialize a Git Repository:

 If your Salesforce project is not already a Git repository, initialize a new Git
repository:

bashCopy code

git init

5. Commit the Metadata:

 Add all the retrieved metadata to the Git repository and commit the changes:

bashCopy code

git add . git commit -m "Initial commit with Salesforce metadata"

6. Create a GitHub Repository:

 Create a new repository on GitHub if you haven't already.

7. Add GitHub Remote:

 Add the GitHub repository as a remote to your local Git repository:

bashCopy code

git remote add origin https://github.com/yourusername/your-repository.git

Replace the URL with your GitHub repository URL.

8. Push to GitHub:

 Push the committed changes to the GitHub repository:

bashCopy code

git push -u origin master

Now, your complete Salesforce sandbox metadata is cloned or copied to the specified GitHub branch.

Keep in mind that managing Salesforce metadata in a version control system requires careful
consideration of the metadata structure and organization. The force:source:retrieve command
retrieves metadata based on the package.xml, so ensure your package.xml file is configured
correctly with the components you need.
how to use a custom connected app and update OauthLocalPort in the sfdx-project.json file.

ChatGPT

ChatGPT

Certainly! Here are the steps to use a custom connected app and update the OauthLocalPort in the
sfdx-project.json file:

Step 1: Create a Custom Connected App

1. Log in to Your Salesforce Org:

 Open your Salesforce instance where you want to create the connected app.

2. Navigate to Connected Apps:

 In Salesforce, go to Setup.

 Enter "App Manager" in the Quick Find box and select App Manager.

3. Create a New Connected App:

 Click on New Connected App.

 Fill in the required details like Connected App Name, API Name, and Contact Email.

 In the API (Enable OAuth Settings) section, check Enable OAuth Settings.

 Set the Callback URL to http://localhost:1718/oauth2/callback (or any port you


choose).

 Add the necessary OAuth scopes based on your requirements.

 Save the connected app.

4. Note Down Consumer Key:

 After saving, note down the Consumer Key from the connected app details. This will
be used during the authentication process.

Step 2: Update sfdx-project.json

1. Open sfdx-project.json:

 Open the sfdx-project.json file in your Salesforce project directory using a text
editor.

2. Update OauthLocalPort:

 Find the "oauthLocalPort" property and set it to the custom port you used in the
connected app's callback URL. For example:

jsonCopy code
"oauthLocalPort": 1718

Step 3: Authenticate Using Custom Connected App

1. Run Auth Command:

 Run the authentication command in your terminal:

bashCopy code

sfdx force:auth:web:login -a YourSandboxAlias -r https://test.salesforce.com -o


https://login.salesforce.com -c

 Replace YourSandboxAlias with the desired alias for your sandbox.

 The -o option specifies the Salesforce login URL.

 The -c option forces the CLI to use the custom connected app.

2. Enter Consumer Key:

 When prompted, enter the Consumer Key you noted down from the custom
connected app.

3. Complete Authentication:

 Follow the prompts in the browser to complete the authentication process.

By following these steps, you should be able to use a custom connected app and update the
OauthLocalPort in the sfdx-project.json file for authentication. This approach helps to resolve port
conflicts and allows you to use a custom connected app for authentication.

Now that you've successfully authenticated with your Salesforce sandbox using Visual Studio Code
and Salesforce CLI, you can proceed to retrieve the complete metadata from the sandbox to your
local machine. Here are the steps:

1. Open Terminal in Visual Studio Code:

 Open Visual Studio Code.

 Press `Ctrl+`` (backtick) to open the integrated terminal.

2. Navigate to Your Project Directory:

 Use the cd command to navigate to your Salesforce project directory.

bashCopy code

cd /path/to/your/sfdx/project

3. Retrieve Metadata:

 Use the force:source:retrieve command to retrieve the complete metadata from


your sandbox. You can specify the metadata components you want to retrieve in a
package.xml file or retrieve everything using a wildcard (*).

For example, to retrieve all metadata:

bashCopy code
sfdx force:source:retrieve -u YourSandboxAlias -x path/to/package.xml

Replace YourSandboxAlias with the alias you used during authentication.

If you want to retrieve everything without specifying components:

bashCopy code

sfdx force:source:retrieve -u YourSandboxAlias

This command will create a force-app directory in your project with all the retrieved metadata.

4. Wait for Retrieval to Complete:

 The retrieval process might take some time depending on the size of your metadata.
Wait for it to complete.

5. Check Your Project Directory:

 After completion, you should see the retrieved metadata in your project directory,
typically under the force-app folder.

Now, you have a local copy of the complete metadata from your Salesforce sandbox in your Visual
Studio Code project. You can start working on your code, making changes, and use version control
systems like Git to manage your Salesforce project.

You might also like