SFDC Stop - Always the latest about Salesforce


Full Tutorial Series with videos, free apps, live sessions, salesforce consulting and much more.


Telegram logo   Join our Telegram Channel
Showing posts with label MavensMate. Show all posts
Showing posts with label MavensMate. Show all posts

Sunday, 10 December 2017

Develop Lightning Components faster using Lightning Data Service

Lightning Data Service allows us to read, create and edit a record without requiring any apex code. There are a number of cool features of Lightning Data Service and I am going to go through some of those features right now:-
  • By using Lightning Data Service you can easily make lightning components that deal with a single record and embed that component to the detail page of that record. 
  • You can even make reusable lightning components that deal with similar data so that they can be reused at multiple record detail pages. 
  • One big advantage of Lightning Data Service is that you don't have to make any apex controller. 
  • Suppose you have two components that work on the same data - one is updating the record and other is displaying the record so as you update the record, the component that is displaying the record is updated automatically and you don't have to take care of any event handling in this case as you normally do in Lightning Components.
  • There are some considerations also that we have to take care while using LDS one of which is that you can only query a single record and that too by Id of that record only while using LDS.
During the starting of this month, I took a session on Lightning Data Service with Noida Salesforce Developer User group at Dreamforce Global Gathering 2017. I have made a presentation for the same and you can view it here and have a more clear idea about the LDS.


During my session, I made multiple lightning components, each for one operation in CRUD. Out of which I gave the demo of read, update and delete operation only but I have the whole code for each operation including create. So let's discuss about each component first and then I'll handover the code to you.

  • Read (LDSComp) - This component displayed the name of the contact.
  • Edit (LDSCompEdit) - This component allows you to edit the contact's first name and last name.
  • Delete (LDSCompDelete) - This component allows you to delete the contact.
  • Create (LDSCompNew) - This component allows you to create a new lead.
There is one more component i.e. LDSWrapperComp in which I wrapped all the components so that I can embed all components together as a single component. The final wrapper component look as follows when you embed it in the record detail page:- 


So, here you can see, I have made four components for each of CRUD operation. What I did is I made this wrapper component reusable. But how ?? As you know that in our Lead as well as Contact both consists of first name and last name fields, so I made a single component and embedded it in both the Lead and Contact detail pages. But as you can see in the last component, I have named it as Create New Lead. This is because, when you create a new record using LDS, you have to give the SObject Type as you load the component initially and I have given my SObject Type as Lead so, in this case whether you embed it in any detail page, it'll create a Lead only.

So let's jump on to the code. You can download the whole code of this LDS demo from here.
If you want to see whole code step by step, you can clone the github repo on your system and then move step by step as I have created 4 different branches in which in each branch one extra component is added to the wrapper component.
You can switch between all 4 branches in the following order:-
  1. read
  2. update
  3. delete
  4. create
More better approach can be if you have setup MavensMate with sublime text to connect with your org, as in that case you have to just create empty components in your actual org and you can go into your org's folder and can set the remote url to my github repo and then switch to particular branch do a git pull and you have the code. But to sync the code to your dev org, you have to make the Lightning Components with same name in your org and then refresh from the server to get those components and then switch to branch and save each file. You may have to delete the .lightning file from the config folder if you are not able to sync the code on saving the file.

If you want to learn how to setup MavensMate you can refer to my other blog post How to setup MavensMate with your favorite text editor for Salesforce.

So, make sure you have tried all the crud operations of LDS by using the code given in the repo. If you have any doubts or problems you can comment below or contact me directly on my twitter handle which is - @rahulcoder

Saturday, 9 December 2017

How to setup MavensMate with your favorite text editor for Salesforce


Sublime Text is my favorite text editor and maybe yours also. But even if you prefer any other text editor, no need to worry as I am going to tell you how to setup MavensMate IDE for salesforce with your favorite text editor. Primarily MavensMate supports:- Sublime Text, Atom or Visual Studio as of now so make sure you choose any one of these.
So, let's move forward step by step:-

Install Sublime Text

Go to https://www.sublimetext.com/ and click on download from the navigation menu at the top, it'll take you to the download page.


Download the file according to your OS and install that.

Setting Up MavensMate

1. Install MavensMate

To install MavensMate, you have to go to it's github repository and in the releases, you can download any version you want to. Once you are on the releases page, you'll see something like this:- 

Click on this link:- https://github.com/joeferraro/MavensMate-Desktop/releases to go directly to the releases page and download the file according to your system. You have different extensions available like:- exe for Windows, dmg for Mac or deb for linux. Download and install it.

2. Create Project

Once you'll open MavensMate, you will see this screen:- 


  • Click on New Project.
  • Select the Environment Type. It can be production, developer, sandbox, prerelease or a custom URL.
  • Click on Connect Button.
  • Login with your Salesforce Credentials.
  • When you login, it may ask for permissions for making changes allow it to do so.
  • Click on the allow button and it'll take you to a new screen where you have to setup your project configuration.
  • Fill up the project details and then click on the advanced tab.
  • Here you'll see you have the information about the metadata that you are fetching from your org. By default some metadata is selected for you like:- ApexClass, ApexTrigger, ApexPages etc. You can add anything you want from Org Metadata to Project Metadata Subscription like here I have added AuraDefinitionBundle to this metadata so that I can fetch and work on Lightning Components as well.
  • Leave the Metadata tab as it is for now and click on Create Project.
  • It may take some time and then you'll end up to the home screen of your project.

  • Cick on Edit Project.
  • On the Edit Project screen, click on Project Metadata Tab, Click on Select All button and click Update Project.
  • It may take some time and then you have your project updated successfully with all the files from your org.
  • Once you have your project updated, you can click on the 2nd last button from the left menu and open the project in Sublime Text or any text editor you have installed.

  • If you are not getting your text editor in here, you can click on settings from the top right corner and you can check and update the installation path of your text editor.
  • You can edit the path here and you may have to restart MavensMate application or your system to see the effect.
As, you have already installed sublime text successfully, let's go on and configure it for MavensMate.

Configuring Sublime Text for MavensMate

  • Go to Tools. Click on Command Pallete.
  • If you have already Package Control installed then no problem, otherwise type package control in the command pallete and install that first.
  • Once you have installed package control, again open the command pallete and type install package and press enter when you see Package Control: Install Package highlighted.
  • It will browse the repositories and fetch it up for you.
  • Once you have the list, type MavensMate and press Enter.

Great...!! You have now MavensMate plugin installed for sublime text and you have configured your text editor for working with Salesforce. You must see MavensMate tab on the right side of help on the top when installed. Now you can code easily here and as you save your file it'll be automatically saved on the Salesforce as shown in the below image:- 


Be careful while using MavensMate as it may override your code on Salesforce when multiple users are working on the same org. It usually show a conflict if there is one but it's a better approach to refresh the files from server before start working. For this you can right click on the folder or file from the left side bar and go to MavensMate->Refresh from Server.




So, In this way you can setup MavensMate with your favorite text editor for Salesforce. Cheers..!!