Intro to Git for Salesforce using VSCode

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this video I'll help you get started using git and GitHub to track your Salesforce customizations what we'll do is retrieve a simple flow from your Salesforce devorg using the Salesforce CLI a manifest file and visual studio code then we'll initialize a local Repository add the files the Salesforce customization files to it and then upload those files to a GitHub account so that they can be shared on the internet all right so let's get started okay the first thing we want to do is open up visual studio code and here if you don't already have a terminal window open you can go to the terminal menu and say new terminal but since I use the terminal all the time I already have one open by default so what we want to do is open our Salesforce org or devorg that already has our simple flow built into it so we do sfdx Force org list and I I've already authorized a few Salesforce orgs on my CLI and so the one we're concerned about here is the one with the Alias client intake so I'll open that org by typing sfdx force or open dash U and we'll use these client intake alias so that'll open up a browser window with our setup already logged in on this instance and here we are in setup so I'll show you that in here we go to flows and I've already built a very simple flow that triggers off of a custom object so this client intake flow right here this just triggers off of a client intake custom object I've created and all it does is turns around and creates a new contact record based on a couple of the fields in the client intake custom object so let's close that guy so what I like to do is open up package manager and let Salesforce bind the flow dependencies for me so if we go into package manager in setup and I create a new package and we can delete this later because we're not actually going to use this for anything other than finding the dependencies I can type client intake flow which you can see I've already done this and we can save that I can go down here to the components and I can add a dependency so in this case we want a low definition so if I hit the F key and get down to flow definition select that you can see that the only custom flow in my org is this client intake flow that I just showed you so let's check that box and say add to package and from there you can see the Salesforce has already discovered that I need the client intake list view I need the client intake custom object that it triggers off of I need a custom field on the contact record that I've created in order to link back to what client intake created the contact record I need the client intake page layout I need the flow definition itself and I also need the client intake custom field that I've put on through the custom object now what we're going to do is go through each of these items and add them to our manifest file but before we do that we have to open up visual studio code and create an sfdx project with a manifest file and Link it to this org so we can use the CLI to retrieve the files so let's minimize this browser window go back to visual studio code and let's go to the command palette Ctrl shift p and say create project with manifest if this doesn't pop up to the top for you you can just type the word create and it'll filter through so we're going to create a project with manifest now the Manifest file is kind of like a manifest on a flight it's a list of all the passengers that go onto a flight in this case it's a list of all the things that make up our package or that we pull down into our project in this case so we want to create an empty project template because we don't want any extra folders that this command actually creates and we're going to call this client intake whoa and I like to put all my files into a Source repo okay so visual studio and the CLI of Salesforce CLI have created this project for us we have a manifest file here called package.xml so if we click on that by default it's telling Salesforce that we want to include all custom Apex classes all custom Apex components Pages test Suites triggers all this kind of stuff we're just doing a simple flow for right now we don't actually use any of these types so we don't use the Apex Trigger type we don't use the Apex test Suite type we're just going to delete all but one of these that we will leave for a template sure where that popped up so let's highlight this hit backspace and now we just have one that we can we can use to get started oh actually the first thing we should be doing is setting our default org to our client intake work so right here we aren't set to the right of work so let's click on that and hopefully our Command palette will pop up to the switch to default org sometimes the first couple times you run extensions here it gets it's a little slow there we go so we want to set our default org oh no we are we're already okay we already had this default org so if I click down here normally I go right into this command palette list and you can see it gives me a list of all the authorized orgs in my Salesforce CLI and in this case we want to scroll down to the client intake org so we're going to click on that and now the client intake organs are default org so now we're all set up now we need to modify our manifest file our packagexml to include all the dependencies that the Salesforce package manager told us we have so let's go back to the Salesforce package manager okay so let's get started adding the package manager manager dependencies to our manifest file in Visual Studio code first of all we're going to skip the list view object here and I'll we'll get back to that in a second we're going to start off with the custom client intake object that triggers our flow so if we go in here and we change the name of the type to custom object and we put in the name of our custom object which is client intake double underscore C which if we go back to our Salesforce instance if we clicked on this open a new tab we want to get the API name as you probably know well that's not the right way to do it here we go object manager client intake C so that's the API name of the object we want to add to our manifest file so there it is now if we save that and right click on the package XML and say retrieve source and manifest from org that will pull down the files that represent our custom object and we can see this objects folder just got created and it has the client intake object which has all the settings that you can set in the Salesforce UI and in addition to that it has the default all list view so that's why we skipped the list view in the first place because when you pull the custom object down you get the list view for free great so now let's move on to the next object for the next dependency of our flow so if we go in here we see that the the contact has a custom field on it that Maps back to the client intake object that created it so let's copy our little template here and we will change the name of this to custom field and we will say contact and let's get the API name of our custom field see where this takes us API name is climbing Tech underscore C double underscore C just as you'd imagine just want to show you how to find it if you're having any trouble so there's the name of the custom field so if we save that go back to our manifest file and say retrieve source we can see that another folder will be created there's our client intake and now we have a contact folder with the client intake field representative so there we go we have all of our object in field files down in Visual Studio code right now so let's close those two tabs we don't need those anymore and let's go look at the the page layout so we need this client intake page layout but these are tricky to uh to find the names of so what I do and this is maybe a little bit lazy but sometimes I like being lazy let's grab another one of these type elements and let's just use the Star Command and we're going to pull down all of the layouts in our org so page layout is the type we want I believe no just layout we just want a layout type well let's get all of them so when we do this it'll pull down into a layout folder all the layouts in our org and we really just want the name of our client intake one so that's that's the name we want right there so if we say rename and include the name of it just copy that we can then go over to our manifest file which is way down here and substitute that for our star go back to our layouts folder and I'll just delete this folder saber manifest file re-download or re-retrieve okay so now we have a layouts folder that only has our client intake in it so a little bit dirty a little bit messy but it's one way to find the name of it quickly okay so now we move on and we need the client intake low definition file so if we go back to our package XML manifest file grab another one of these types type elements and we want low is the type name and our the name of our flow is client intake flow let's have underscores I believe it has underscores okay so we save that retrieve source and manifest and now we have the XML file that defines our little custom flow here okay so we're almost there oh we already have the custom field for the email on the client intake object if you go back here that came down when we got the object so if I go back to my objects and say client intake and go to Fields there's already a custom email field there great so we officially have all the files that Salesforce says this flow depends on so at this point it's a good this is a good point where we can create our git Repository so in order to add these files to git the first thing you have to do is go to this Source control tab or I'm not sure what they call these menu items but this guy this is the official git symbol so you click on that and you say it says this folder is not currently I get repository so we want to make this folder a git repository click this button and now all of these files are eligible to be added to git now the problem is we don't actually want to add a lot of these files to git so all of these CLS files uh are just part of a standard sfdx project so you see everything has sfdx as the folder name we don't want sfdx folder and we don't want the SF folder so the standard way to not add certain kinds of files to get or certain folders to get is to create what's called a git ignore file so we'll do that now go to file explorer and in the root of your project you create a file called dot get ignore just like that and in here we can just list those two directory so we can say dot SF we don't want and we can say dot sfdx we don't want and as soon as I save that file you see over here where it says 72 it's saying 72 files are eligible to be added to get right now but once we save this git ignore file that number goes down to 13. so now we're ignoring those two directories the dot SF and the dot sfdx directories and you can see now these files are the ones we actually want to put into our git repo there are custom object definition XML files our manifest file and some Json files that Define the sfdx project great so let's just add all those guys let's do it the kind of clunky way here there's probably a better way to do this I usually use get on the command line so I'm not real well versed in how the uh the vs code git UI works but here we go it's at the the ugly way okay and then in here you really want to add a message because what we just did we just added the files to what's called a commit so git Works in commits uh you can think of a commit as just a package of changes that are labeled and you can jump between those change packages you can jump between those commits and see different versions of your of your files so in this case this is our first commit so we're going to say initial commit of the client intake flow and we're going to say commit now we've committed to get our changes now if we want to make those changes available on GitHub so that other people that don't have access to our computer can access our files we can click this publish Branch button and it'll ask us okay do you want to publish to a private GitHub repository that no one can see without your permission or would you like to make it public on the internet for everyone to see they can clone it which means they can download it to their computers and they can potentially Fork it we're going to create a public repository because I want you guys to be able to see this so let's click on that and that will automatically create a new Repository under my GitHub account and it says successfully published client intake flow with my username to GitHub so we can go look at that by clicking open on GitHub and you can see all those files that make up our sfdx project are on GitHub so let's click that you can see our folders if you click objects there's our client intake object and then there's our one client intake custom I'm sorry our one custom field on the contact object so now anyone that wants to collaborate on your project can go to your GitHub account and download those files okay so the next step here is to make changes to our files and see what putting our files in the git and GitHub gets us from a change tracking perspective so if I go back to my object manager in my development org here and let's go find our client intake object and let's just add a new field to our client intake object just to add a text field and I'm going to say description pretty common thing to put on to an object we'll get a length of 128. and we'll save that so now that we have another custom field on our custom object I can go back to visual studio code and I can go straight to our package XML so because we have the entire custom object the entire client intake custom object specified under manifest file I can right click on package XML retrieve source and it'll automatically pull down that new field so you see there it popped up there's the description field we just created so that's great now you can see here git has detected that we've changed two files you can see it changed the layout file to add the New Field and we got a new file that represents the new field so if we add both of those new files or one new file and one modified file to our commit and say in our commit message added new description field to the client intake object and hit commit we've now added another package of changes in this case it's only two files to our git repository and the sync changes button will push those two changes up to our GitHub repository on yeah it says this action will pull and push so if someone else had made changes to our GitHub repository we'd also be pulling down those changes as part of this operation but we're the only people working on this rehab repo so it's just going to be a push and there we go our changes have been committed to our GitHub repo so let's go back to our GitHub account and if we refresh here we can see that most of the files came up on our initial commit so the the commit message from the first commit is here but you can see that the second commit message is here so if I go into these this folder I can see which was the last commit of each of these files so if we go to object and the client intake object and look at our new description field you can see it has that second commit message on it now if I go up a directory I can actually look at what makes up a commit so you can see it's it can see that in that commit we added the field to the layout file and we also added all the contents of the description file now to get into more how you use git and GitHub to compare commits and change sets that's probably too big for this video but you can kind of see how this might might be a useful way to start working with the team thank you for watching and we'll see you next time
Info
Channel: Mitch Routt
Views: 12,132
Rating: undefined out of 5
Keywords: Git, GitHub, Premiere_Elements_2023, SFDX, Salesforce, Salesforce CLI, VSCode, Visual Studio Code
Id: yBp8Le3Fw4M
Channel Id: undefined
Length: 22min 31sec (1351 seconds)
Published: Tue Feb 28 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.