Deprecated: Optional parameter $list declared before required parameter $is_script is implicitly treated as a required parameter in /home1/oijoiv2f/public_html/wp-content/plugins/apus-framework/libs/redux/ReduxCore/inc/class.redux_cdn.php on line 21

Deprecated: Optional parameter $register declared before required parameter $footer_or_media is implicitly treated as a required parameter in /home1/oijoiv2f/public_html/wp-content/plugins/apus-framework/libs/redux/ReduxCore/inc/class.redux_cdn.php on line 45

Deprecated: Optional parameter $register declared before required parameter $footer_or_media is implicitly treated as a required parameter in /home1/oijoiv2f/public_html/wp-content/plugins/apus-framework/libs/redux/ReduxCore/inc/class.redux_cdn.php on line 104

Deprecated: Optional parameter $expire declared before required parameter $path is implicitly treated as a required parameter in /home1/oijoiv2f/public_html/wp-content/plugins/apus-framework/libs/redux/ReduxCore/inc/class.redux_functions.php on line 54

Deprecated: Optional parameter $depth declared before required parameter $output is implicitly treated as a required parameter in /home1/oijoiv2f/public_html/wp-content/themes/entaro/inc/classes/megamenu.php on line 155

Deprecated: Optional parameter $depth declared before required parameter $output is implicitly treated as a required parameter in /home1/oijoiv2f/public_html/wp-content/themes/entaro/inc/classes/mobilemenu.php on line 147

Deprecated: Optional parameter $args declared before required parameter $wp_customize is implicitly treated as a required parameter in /home1/oijoiv2f/public_html/wp-content/plugins/apus-framework/libs/redux/ReduxCore/inc/extensions/customizer/extension_customizer.php on line 583

Deprecated: Optional parameter $args declared before required parameter $wp_customize is implicitly treated as a required parameter in /home1/oijoiv2f/public_html/wp-content/plugins/apus-framework/libs/redux/ReduxCore/inc/extensions/customizer/extension_customizer.php on line 606

Warning: Cannot modify header information - headers already sent by (output started at /home1/oijoiv2f/public_html/wp-content/plugins/apus-framework/libs/redux/ReduxCore/inc/class.redux_cdn.php:21) in /home1/oijoiv2f/public_html/wp-includes/feed-rss2.php on line 8
Can we Include One Lightning component to another Archives - Salesforce Next Gen https://salesforcenextgen.com/tag/can-we-include-one-lightning-component-to-another/ Trailhead and Beyond Mon, 28 Dec 2020 19:36:47 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.2 https://salesforcenextgen.com/wp-content/uploads/2020/10/cropped-76dc0dd6-326a-4956-a412-bfdf20c7fb23_200x200-32x32.png Can we Include One Lightning component to another Archives - Salesforce Next Gen https://salesforcenextgen.com/tag/can-we-include-one-lightning-component-to-another/ 32 32 How to create a Modal box in Lightning Component? https://salesforcenextgen.com/how-to-create-a-modal-box-in-lightning-component/ https://salesforcenextgen.com/how-to-create-a-modal-box-in-lightning-component/#respond Wed, 20 Jun 2018 18:00:38 +0000 http://www.salesforcenextgen.com/?p=1330 How to create a Modal box in Lightning Component? In this post we are going to create a on demand Modal box or Pop Over, using the standard library provided by salesforce. Modal boxes are used to display messages which requires user’s attention and is therefore displayed in foreground interrupting user’s workflow and seeking attention. …
Continue reading How to create a Modal box in Lightning Component?

The post How to create a Modal box in Lightning Component? appeared first on Salesforce Next Gen.

]]>
How to create a Modal box in Lightning Component?

MODAL Box

In this post we are going to create a on demand Modal box or Pop Over, using the standard library provided by salesforce.

Modal boxes are used to display messages which requires user’s attention and is therefore displayed in foreground interrupting user’s workflow and seeking attention.

For the Modal we use a single tag provided to us by salesforce i.e. <lightning:overlayLibrary aura:id=”overlayLib”/> , we need to make sure that we use this tag only in lightning experience, lightning Communities and salesforce app only.

This single tag is used wherever we want to display the Message or popover view. There are some more custom components required for this tag to work properly which we are going to create as shown below.

What the content of this Modal box contains, for this we create a lightning component with name modalContent and will have two attributes for now i.e. a icon and the content to display. For this example, I have written static text, as shown below.

<aura:component implements=”force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction” access=”global” >

<lightning:icon size=”medium” iconName=”action:approval” alternativeText=”Approved” />

Your application has been approved.

</aura:component>

Now in the main component we call this modalComponent and the parent component will display the modal content. Below is the code of the parent component.

<aura:component implements=”force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction” access=”global” >

<lightning:overlayLibrary aura:id=”overlayLib”/>

<lightning:button name=”modal” label=”Show Modal” onclick=”{!c.handleShowModal}”/>

</aura:component>

You see here we do not directly place the modalContent in the component but we create the modalContent on click of the button in the controller of the Parent component as shown below.

({

handleShowModal: function(component, evt, helper) {

var modalBody;

debugger;

$A.createComponent(“c:modalContent”, {},

function(content, status) {

if (status === “SUCCESS”) {

modalBody = content;

component.find(‘overlayLib’).showCustomModal({

header: “Application Confirmation”,

body: modalBody,

showCloseButton: true,

cssClass: “mymodal”,

closeCallback: function() {

alert(‘You closed the alert!’);

}

})

}

});

}

})

Now we can put this component anywhere in the lightning experience and it will work immediately without writing the SLDS for the Modal box.

Let’s discuss the methods provided by the salesforce in this example, first we used the method $A.createComponents(), this method is used to create the lightning component on the go i.e. dynamically. Then in this method we call our custom component modalContent as ‘c:modalContent’. Next in the callback function we find our tag using the aura:id and method component.find(). After this we call method showCustomModal() which is a callback method and this method take couple of attributes such as header, body, showclosebutton, cssClass and closeCallback. This is how it looks as shown below.

MODAL Box

Open Modal Button

MODAL Box

Modal Box

MODAL Box

Alert after closing Modal Box

As soon as we click on the lightning button, handleshowModal method is called from the client-side controller. And this how you use the lightning:overlayLibrary for Modal box.

Happy Coding.

Also, Have a look at the below resources:

  1. Best Salesforce Interview Questions book with Apex and Visualforce concept explained

Also, Have a look at the below learning resources:

  1. SOQL (Salesforce Object Query Language)

  2. Apex Trigger Best Practices and the Trigger Framework

  3. Salesforce Interview Question and Answers Part 2

  4. Salesforce Interview Questions on Test Class

  5. Salesforce-lightning-interview-questions-2018

     6. Salesforce Interview Questions Batch Clas

The post How to create a Modal box in Lightning Component? appeared first on Salesforce Next Gen.

]]>
https://salesforcenextgen.com/how-to-create-a-modal-box-in-lightning-component/feed/ 0
How to send parameters in AuraEnabled methods in Salesforce Lightning Components? https://salesforcenextgen.com/send-parameters-in-auraenabled-methods/ https://salesforcenextgen.com/send-parameters-in-auraenabled-methods/#respond Mon, 16 Apr 2018 16:46:42 +0000 http://www.salesforcenextgen.com/?p=1323 How to send parameters in AuraEnabled methods in Salesforce Lightning Components? Passing value to and fro from the Lightning component is one of the task which is done on day to day basis, this post deals with the concern that how to pass values from the client side Javascript controller to the AuraEnabled Apex Controller …
Continue reading How to send parameters in AuraEnabled methods in Salesforce Lightning Components?

The post How to send parameters in AuraEnabled methods in Salesforce Lightning Components? appeared first on Salesforce Next Gen.

]]>
How to send parameters in AuraEnabled methods in Salesforce Lightning Components?

Passing value to and fro from the Lightning component is one of the task which is done on day to day basis, this post deals with the concern that how to pass values from the client side Javascript controller to the AuraEnabled Apex Controller at server side.

Salesforce Lightning Training

Passing values from client side needs the following requirement as mentioned below :

  1. An attribute in the component mark up to hold the value which is sent.
  2. An AuraEnabled Server side controller method that accepts the value.
  3. A JavaScript controller on client side to send the value from client side to server side.

Below is an example of a simple component which contains a string attribute and its javascript controller sends this attribute to the server side controller, where this controller perform some basic task on it.

Component’s mark-up is below

<aura:component controller=”serverSideCntrllr”>

  <aura:handler name=”init” value=”{!this}” action=”{!c.callingServer}”/>

  <aura:attribute name=”myAttribute” type=”String” default=”Hello World”/>

</aura:component>

JavaScript controller Code is given below

({

                callingServer : function(component, event, helper) {

          var myAttribute = component.get(“v.myAttribute”);

          var action = component.get(“c.setAttribute”);

          action.setParams({ “myString” : myAttribute });

          action.setCallback(this, function(response) {

        

            var state = response.getState();

            if (state === “SUCCESS”) {

              // Do stuff

            }

            else {

              console.log(state);

            }

          });

          $A.enqueueAction(action);

                }

})

Server side AuraEnabled Code is given below

public class serverSideCntrllr {

    @AuraEnabled

    public static void setAttribute(String myString) {

      System.debug(myString);

    }

}

In the example above, we can see that the type of the attribute sent is basic string type, therefore when this value is passed to the server side controller than it works fine, but this is not the case for each data type. You have to perform few tweaks before you can send the value and sometime you have to perform some actions after the value is received at the server side. We will see these tweaks in below examples.

Passing Integer as a value from client side server.

Integer

Interger is value which is a basic type and easily passed from the client side without making any changes, but at the server side we need to first convert this value into integer and then we can perform the numerical task related to the integer, as shown below in the example.

First define an integer type attribute in the component as shown below.

<aura:component controller=”serverSideCntrllr”>

  <aura:handler name=”init” value=”{!this}” action=”{!c.callingServer}”/>

  <aura:attribute name=”myAttribute” type=”String” default=”Hello World”/>

  <aura:attribute name=”IntegerVar” type=”Integer” default=”1″/>

</aura:component>

Then make the change in the JavaScript Controller as shown below.

({

            callingServer : function(component, event, helper) {

          var IntegerVar = component.get(“v.IntegerVar”);

          var action = component.get(“c.setInteger”);

          action.setParams({ “myInteger” : IntegerVar });

          action.setCallback(this, function(response) {

        

            var state = response.getState();

            if (state === “SUCCESS”) {

              // Do stuff

            }

            else {

              console.log(state);

            }

          });

          $A.enqueueAction(action);

            }

})

Then the AuraEnabled method as shown below.

@AuraEnabled

    public static void setInteger(String myInteger) {

      System.debug(myInteger);

    }

This code runs fine when we execute the system.debug statement but, when we try to perform a numerical operation, this method will start producing the following error : FATAL_ERROR Internal Salesforce.com Error.

myInteger++;

We are facing this error because, it is due to the improper casting of the integer variable by the framework. Therefore before we could use this variable as an integer, we need to first cast it into the correct type as shown below.

myInteger = Integer.valueOf(myInteger);
myInteger++;

This is a good work around till the framework does not address this issue.

sObject

sObjects are easy to send and receive between server side and client side controller everything is handled perfectly by the framework and we do not need to worry about any casting related issue with sObject.

The only issue is that the relationships are not available in the apex method and with the new lightning data service, we might not even have to query the record anymore.

Date

You will not be able to send Date variable as a value in the client side controller, in this case we have to tweak this data type at client side and then pass it to server side controller and then again cast it to date at the server side controller.

Create the Date attribute at the component as shown below.

<aura:attribute name=”myDate” type=”Date” default=”1981–08–26″/>

Javascript controller as shown below.

({

            callingServer : function(component, event, helper) {

          var myDate = component.get(“v.myDate”);

          var action = component.get(“c.setInteger”);

          action.setParams({ “myInteger” : JSON.stringify(myDate ) });

          action.setCallback(this, function(response) {

        

            var state = response.getState();

            if (state === “SUCCESS”) {

              // Do stuff

            }

            else {

              console.log(state);

            }

          });

          $A.enqueueAction(action);

            }

})

Server side controller as shown below.

@AuraEnabled
public static void setDate(String myDate) {
Date myNewDate = Date.valueOf(myDate);
}

Apex Classes

The next encounter with error would be when you are going to send a wrapper class as an argument from client side to server side, in this scenario we have to make tweak in the value passed both at the client side and as well as at the server side.

To test this we first create a wrapper class as shown below

public class NewTestWrapperClass {
@AuraEnabled
public String label {get; set;}
}

Then we first create a component attribute as an apex class.

<aura:attribute name=”myClass” type=” NewTestWrapperClass” />

Normal javascript Controller would be

({

            callServer : function(component, event, helper) {

      var myClass = component.get(“v.myClass”);

      var action = component.get(“c.setClass”);

      action.setParams({ “myClass” : myClass });

      action.setCallback(this, function(response) {

        // Do stuff

      });

      $A.enqueueAction(action);

    }

})

And Apex Controller method would be

@AuraEnabled

    public Static void setClass(NewTestWrapperClass myClass) {

      System.debug(myClass);

    }

But this would lead to the fatal error and we would not be able to find the desired output. The best work around to this situation is to convert the argument into the relative JSON string and then Deserialise this string in the Apex Controller at the server. We convert the wrapper class object into the JSON string by using the Javascript method JSON.stringyfy as shown below

({

            callServer : function(component, event, helper) {

      var myClass = component.get(“v.myClass”);

      var action = component.get(“c.setClass”);

      action.setParams({ “myClass” : JSON.stringify(myClass) });

      action.setCallback(this, function(response) {

        // Do stuff

      });

      $A.enqueueAction(action);

    }

})

And the tweak performed at the server side would be something like this.

@AuraEnabled

    public Static void setClass(NewTestWrapperClass myClass) {

      NewTestWrapperClass nwc = (NewTestWrapperClass)JSON.deserialize(myClass, NewTestWrapperClass.class);

    }

So if you faced a problem similar to the one mentioned above then you have workaround till the framework fixes the issues.

Happy Coding.

Also, Have a look at the below resources:

  1. Best Salesforce Interview Questions book with Apex and Visualforce concept explained

Also, Have a look at the below learning resources:

  1. SOQL (Salesforce Object Query Language)

  2. Apex Trigger Best Practices and the Trigger Framework

  3. Salesforce Interview Question and Answers Part 2

  4. Salesforce Interview Questions on Test Class

  5. Salesforce-lightning-interview-questions-2018

     6. Salesforce Interview Questions Batch Class 

The post How to send parameters in AuraEnabled methods in Salesforce Lightning Components? appeared first on Salesforce Next Gen.

]]>
https://salesforcenextgen.com/send-parameters-in-auraenabled-methods/feed/ 0
How to use lightning accordion https://salesforcenextgen.com/lightning-accordion-example/ https://salesforcenextgen.com/lightning-accordion-example/#comments Mon, 09 Apr 2018 17:43:32 +0000 http://www.salesforcenextgen.com/?p=1318 How to use lightning accordion and how to dynamically add accordion section in lightning. In this post we are going to create a lightning accordion component with static text and then we are going to fetch list of contacts and display their detail in the accordion section. To begin this quest we are first going …
Continue reading How to use lightning accordion

The post How to use lightning accordion appeared first on Salesforce Next Gen.

]]>
How to use lightning accordion and how to dynamically add accordion section in lightning.

In this post we are going to create a lightning accordion component with static text and then we are going to fetch list of contacts and display their detail in the accordion section.

Salesforce Lightning Tutorials

To begin this quest we are first going to create an apex class which we will use to fetch the contact records and information related to each contact record.

Below is the code of the apex controller class fetchContactDetails:

public class fetchContactDetails {   

    @AuraEnabled

    public static list<Contact> fetchContactList(){

        return [select Id, name, Account.name, Email from contact limit 10];             

    }

}

This class contains an Aura Enabled method which returns a list of 10 contacts with their record Id, Name, Account Name and Email. We use this information and display for each contact record as accordion section later in this example.

Now we are going to create a lightning component which will represent each contact records as the body of each accordion section. I am naming this component as eachContactCard, its code is written below.

<aura:component implements=”flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes” access=”global” >

    <aura:dependency resource=”markup://force:navigateToSObject” type=”EVENT”/>

    <aura:attribute name=”objContact” type=”Contact” />

    <aura:attribute name=”showButton” type=”Boolean”/>

  <div class=”demo-only” style=”width: 30rem;”>

    <article class=”slds-tile”>

        <h3 class=”slds-tile__title slds-truncate” title=”Contacts UX”><a href=”javascript:void(0);”>Contacts UX</a></h3>

        <div class=”slds-tile__detail”>

            <aura:if isTrue=”{!v.showButton }”>

                <lightning:button label=”Full Details” onclick=”{!c.onFullDetails}”/>               

            </aura:if>         

           

            <dl class=”slds-list_horizontal slds-wrap”>

                <dt class=”slds-item_label slds-text-color_weak slds-truncate” title=”First Label”>Contact Name:</dt>

                <dd class=”slds-item_detail slds-truncate” title=”Description for first label”>{!v.objContact.Name}</dd>

                <dt class=”slds-item_label slds-text-color_weak slds-truncate” title=”Second Label”>Account Name:</dt>

                <dd class=”slds-item_detail slds-truncate” title=”Description for second label”>{!v.objContact.Account.Name}</dd>

                <dt class=”slds-item_label slds-text-color_weak slds-truncate” title=”Third Label”>Email:</dt>

                <dd class=”slds-item_detail slds-truncate” title=”Description for Third label”>{!v.objContact.Email}</dd>           

                </dl>

    </div>

    </article>

  </div>

</aura:component>

This component takes contact object as an attribute which provides us with the required information to display, this value would be provided by the parent component of this component and I will discuss about that, when we define it. In this component we created a lightning button as well which onclick will navigate to the detail page of the sObject. OnClick of this button a method from the JS controller of the component is called i.e. ‘onFullDetails’. The definition of this method is written in the controller and its code is below:

({

                 onFullDetails : function(component, event, helper) {

        debugger;

        var currentRecordId = component.get(“v.objContact.Id”) ;

        alert(currentRecordId);

                                var navEvt = $A.get(“e.force:navigateToSObject”);

        navEvt.setParams({

          “recordId”: component.get(“v.objContact.Id”),

          “slideDevName”: “detail”

        });

        navEvt.fire();

                },

    doInIt : function(component, event, helper){

                                var navEvt = $A.get(“e.force:navigateToSObject”);

        if(navEvt){

            component.set(“v.showButton”, true);

        }else{

            component.set(“v.showButton”, false);

        }

    }

})

onFullDetails method fetch’s the event forece:NavogateToSobject and sets it params with the record id of the contact and navigates to the detail of the respective contact. There is one more method defined in the controller which is checking whether this event is available or not, because the methods force:NavigateTOSObject works only in lightning pages and Salesforce1 App other than that we get an error message at run time .

So now we have created an Apex class which is return list of contacts and we have created a component which is going to display the information of each record now we are going to create the parent component which will receive the list of contacts will display them as an accordion and the details of the contact as the accordion section. But first will discuss how to create a accordion with static text.

<aura:component>

   <lightning:accordion activeSectionName=”B”>

     <lightning:accordionSection name=”A” label=”Accordion Title A”>This is the content area for section A</lightning:accordionSection>

     <lightning:accordionSection name=”B” label=”Accordion Title B”>This is the content area for section B</lightning:accordionSection>

     <lightning:accordionSection name=”C” label=”Accordion Title C”>This is the content area for section C</lightning:accordionSection>

   </lightning:accordion>

</aura:component>

This will be displayed as something like this:

Salesforce Lightning Tutorials

Now to are going to make this component dynamic and to do so we first need to add an apex controller which provide it a list of contacts (fetchContactDetails), then we write its JS Controller to set the returned list from the Apex controller on the component as shown below

<aura:component controller=”fetchContactDetails” implements=”flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId” access=”global” >

    <aura:attribute name=”contactList” type=”contact[]” />

                <aura:handler name=”init” value=”{!this}” action=”{!c.doInit}” />   

                 <lightning:accordion activeSectionName=”A    “>

         <aura:iteration items=”{!v.contactList}” var=”item”>

             <lightning:accordionSection label=”{! ‘Contact Name :’ + item.Name}” name=”{!item.Name}”>

                   <c:eachContactCard objContact=”{!item}” />               

         </lightning:accordionSection> 

    </aura:iteration>    

  </lightning:accordion>

</aura:component>

In this component we create an attribute to hold the list of contact at the runtime and we call doInIt method of JS controller to call the Apex class the set the returned list of contacts on the initialisation of the component. Then we create a lightning Accordion and since we are fetching each accordion section dynamically we use Aura:Iteration and bind it with contact list.

Inside Aura:Iteration, we create a lightning accordion section whose label which displayed whether the section is active or not and its text set dynamic based on the returned list of records. In this section we put our eachContactCard and provide it with the objContact Attribute.

This element will repeat till the end of the list of Contacts, in our case we fetched 10 contact records, therefore we have 10 accordion sections with details of each records.

Below is the code for JS Controller

({

                doInit : function(component, event, helper) {

                                var action = component.get(“c.fetchContactList”);       

        action.setCallback(this, function(data){

            component.set(“v.contactList”,data.getReturnValue());

        });       

        $A.enqueueAction(action);

                }  

})

We now add this component to the test app so that we can preview the created component.

<aura:application extends=”force:slds” >

    <c:accordianTest />

</aura:application>

Below is the screenshot of the desired output.

Salesforce Lightning Tutorials

Also, Have a look at the below resources:

  1. Best Salesforce Interview Questions book with Apex and Visualforce concept explained

Also, Have a look at the below learning resources:

  1. SOQL (Salesforce Object Query Language)

  2. Apex Trigger Best Practices and the Trigger Framework

  3. Salesforce Interview Question and Answers Part 2

  4. Salesforce Interview Questions on Test Class

  5. Salesforce-lightning-interview-questions-2018

     6. Salesforce Interview Questions Batch Class 

The post How to use lightning accordion appeared first on Salesforce Next Gen.

]]>
https://salesforcenextgen.com/lightning-accordion-example/feed/ 1
How to fetch and display list of records in Lightning Component https://salesforcenextgen.com/display-list-of-records-in-lightning-component/ https://salesforcenextgen.com/display-list-of-records-in-lightning-component/#respond Mon, 09 Apr 2018 17:31:06 +0000 http://www.salesforcenextgen.com/?p=1312 How to fetch and display list of records in Lightning Component? In this post we are going to create a basic lightning application which will have two lightning components. Before you begin going through this post kindly make sure that you have understanding of lightning components and how they work. A lightning component bundle is …
Continue reading How to fetch and display list of records in Lightning Component

The post How to fetch and display list of records in Lightning Component appeared first on Salesforce Next Gen.

]]>
How to fetch and display list of records in Lightning Component?

In this post we are going to create a basic lightning application which will have two lightning components. Before you begin going through this post kindly make sure that you have understanding of lightning components and how they work.

Salesforce Lightning Tutorial

A lightning component bundle is comprised of following resources.

  1. A UI component which provides a user interface to interact with the system.
  2. An Apex controller if you are making a server call from the UI component.
  3. A client side controller and helper to interact with the component at client side.

To begin the code we need to log in to the Salesforce org in lightning experience mode and then click on the Gear icon on the right side top corner and click on developer console.

Once the developer console opens, we first need to create a Lightning Application. We name this as testApp. The sole purpose of this lightning application is to test the lightning component we are going to create. We create lightning application because this is the only component which has a preview in the right side bar.

Salesforce Lightning Tutorial

To include the lightning design system CSS for this application we need to extend our application with force:slds, this one line code will include the required css for the whole application.

Below is the code of our raw  application

Salesforce Lightning Tutorial

Now to accomplish the task of displaying a list of contacts we need to first analyse that how we can decompose this request into small components. i.e. a list of record will have detail of a single record in each line. Therefore each line of record can be an individual component and can be repeated and iterated over till the end of records.

To begin with we need to understand that how many fields we are going to display for each record, for this example we are going to display contact name, account name of the contact and email address of the contact. So for this we are going to create a component which will have 3 aura attribute’s namely contactName, accountName and email.

We then use these attributes to display the contact as a tile for each record. We are naming the component as eachContactCard. Below is the code of the component.

<aura:component implements=”flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes” access=”global” >

    <aura:attribute name=”contactName” type=”String” />

    <aura:attribute name=”accountName” type=”String” />

    <aura:attribute name=”email” type=”String” />    

  <div class=”demo-only” style=”width: 30rem;”>

    <article class=”slds-tile”>

        <h3 class=”slds-tile__title slds-truncate” title=”Contacts UX”><a href=”javascript:void(0);”>Contacts UX</a></h3>

        <div class=”slds-tile__detail”>

            <dl class=”slds-list_horizontal slds-wrap”>

                <dt class=”slds-item_label slds-text-color_weak slds-truncate” title=”First Label”>Contact Name:</dt>

                <dd class=”slds-item_detail slds-truncate” title=”Description for first label”>{!v.contactName}</dd>

                <dt class=”slds-item_label slds-text-color_weak slds-truncate” title=”Second Label”>Account Name:</dt>

                <dd class=”slds-item_detail slds-truncate” title=”Description for second label”>{!v.accountName}</dd>

                <dt class=”slds-item_label slds-text-color_weak slds-truncate” title=”Third Label”>Email:</dt>

                <dd class=”slds-item_detail slds-truncate” title=”Description for Third label”>{!v.email}</dd>           

                </dl>

    </div>

    </article>

  </div>

</aura:component>

Since this component will receive value of its attribute from the parent component, therefore we do not require any client side controller or server side controller for this component. Now we are going to create the parent component to hold and display the list of the contacts.

We are going to name this component as listOfContacts, this component will have attribute to hold a list of contacts and as this component is going to fetch records from server side we are going to mention the apex controller in this component and we also want to display the component therefore we create a client side controller and write an aura handler method which would run to initialise the component as shown below. We also create an aura iteration component which is going to iterate over the list of the contacts and will use the eachContactCard component to display each record. As shown below:

<aura:component controller=”fetchContactDetails” implements=”flexipage:availableForAllPageTypes” access=”global” >

    <aura:attribute name=”contactList” type=”contact[]” />

                <aura:handler name=”init” value=”{!this}” action=”{!c.doInit}” />   

     <aura:iteration items=”{!v.contactList}” var=”item”>

         <c:eachContactCard contactName=”{!item.Name}” accountName=”{!item.Account.Name}” email=”{!item.Email}”  />

         <br/>

    </aura:iteration>

</aura:component>

Apex Controller of this component is fetchContactDetails and its method fetchContactList returns the list of contacts, this method as it is going to be called in lightning component we have to declare this with annotation @AuraEnabled and any method which has @AuraEnabled attribute has to be declared as public static,  as shown below

public class fetchContactDetails {   

    @AuraEnabled

    public static list<Contact> fetchContactList(){

        return [select Id, name, Account.name, Email from contact limit 10];             

    }

}

The client side controller which displays the list of contact, in this controller we have declared a method doInit. This method calls the method declared in Apex controller and sets the view tiem value of the contactList attribute at the run time as shown below.

({

                doInit : function(component, event, helper) {

                                var action = component.get(“c.fetchContactList”);       

        action.setCallback(this, function(data){

            component.set(“v.contactList”,data.getReturnValue());

        });       

        $A.enqueueAction(action);

                }

})

Once you have created all the components then change the lightning application code as shown below

<aura:application extends=”force:slds” >

    <c:listOfContacts />

</aura:application>

Then click on the preview button to display the list of contacts.

Salesforce Lightning Tutorials

Happy Coding……

Also, Have a look at the below resources:

  1. Best Salesforce Interview Questions book with Apex and Visualforce concept explained

Also, Have a look at the below learning resources:

  1. SOQL (Salesforce Object Query Language)

  2. Apex Trigger Best Practices and the Trigger Framework

  3. Salesforce Interview Question and Answers Part 2

  4. Salesforce Interview Questions on Test Class

  5. Salesforce-lightning-interview-questions-2018

     6. Salesforce Interview Questions Batch Class 

The post How to fetch and display list of records in Lightning Component appeared first on Salesforce Next Gen.

]]>
https://salesforcenextgen.com/display-list-of-records-in-lightning-component/feed/ 0
Top 50 Salesforce Lightning Interview Questions 2018 https://salesforcenextgen.com/salesforce-lightning-interview-questions-2018/ https://salesforcenextgen.com/salesforce-lightning-interview-questions-2018/#comments Wed, 07 Feb 2018 08:55:57 +0000 http://www.salesforcenextgen.com/?p=1223 Salesforce Lightning Interview Questions Below is the comprehensive list of questions asked in Salesforce Lightning Interview Questions. 1. What are the type of events into Salesforce Lightning component? a. Application Event – Scope of this event is throughout the lightning App and any component which has registered for this event would get a notification. b. …
Continue reading Top 50 Salesforce Lightning Interview Questions 2018

The post Top 50 Salesforce Lightning Interview Questions 2018 appeared first on Salesforce Next Gen.

]]>
Salesforce Lightning Interview Questions

Salesforce Lightning Interview Questions Below is the comprehensive list of questions asked in Salesforce Lightning Interview Questions.

1. What are the type of events into Salesforce Lightning component?

a. Application Event – Scope of this event is throughout the lightning App and any component which has registered for this event would get a notification.
b. Component Event– Scope of this event is within itself or the parent component of this event, all the components declared within the parent component would get notified of this event.
c. System Event- these are the events fired by Salesforce’s system during the lifecycle of the lightning app.

2. What are the basic differences between Application Event and Component Event?

Component events are used to do communication between child and parent. They use bubbling and capture same as used in DOM events. A change in a child component can be communicated to the parent component via component event.

Application events are used to communicate any change in the component to a broader audience. Any component who has registered for this event will get a notified.
To use Component Event API we use the below syntax

3. When should we use Component event and application events?

It is best to always use a component event instead of an application event. Component events can only be handled by components above them in the containment hierarchy, therefore, their usage is localized to the components that need to know about them.

Application events are best used for something that should be handled at the application level, such as navigating to a specific record. Application events allow communication between components that are in separate parts of the application and have no direct containment relationship.

4. Which interface we are supposed to implement so that a lightning component can be used as quick action?

We need to implement the following “force: lightningQuickAction” so that we can use the component as a Quick Action

5. Which interface we are supposed to implement so that a lightning component can be used as a Tab?

We need to implement the following “force:appHostable” so that we can use the component as a Tab

6. How can we use a lightning component in a VisaulForce Page? Explain?

A Lightning component can be embed in any webpage using a very powerful and flexible feature, Lighting out. When used with Visualforce some complexity becomes simpler.
Lightning component can be added to Visualforce page in three steps:

1. We have to first Add the Lightning Components for Visualforce JavaScript library to your targetted Visualforce page using the tag.

2. Next we have to create and refer a Lightning app which is used to the component dependencies.

3. Lastly we need to write a JavaScript function which will finally create the the component on the page using $Lightning.createComponent()

7. How can we call child component controller method from the parent component controller method?

To call a child component’s controller method, we need to first create a aura:method which is publically accessible, aura:method is used to communicate down the containment hierarchy i.e. parent to child. Sample code for implementing the aura method:
Component code

Controller
({
publicmethod: function(cmp, event) {
var params = event.getParam(‘arguments’);
if (params) {
var message = params. str;
console.log(“message: ” + message);
return message;
}
}
})

Calling the cild method from parent controller
({
callchildCompMethod : function(component, event, helper) {
var childCmp = component.find(“childCompName”);
var Result =
childCmp. publicmethod (“message sent by parent component”);
console.log(“Result: ” + Result);
}
})

8. What are the different Lightning component bundles?
a. Component
b. Controller
c. Helper
d. Style
e. Document
f. Design
g. SVG
h. Rendrer

9. How to ensure FLS while working with Lightning Component?

FLS and CRUD are not automatically enforced in the lightning component whenever any object is referenced in the Apex Controller and the component will display the fields and records for which the users do not have access. Therefore we should manually enforce the FLS and CRUD in the Apex Controller, or we should try to use Lightning Data service wherever possible because it takes care of FLS and CRUD for us.

10. How can we use Lightning Components with the Salesforce1 Mobile App ?

For this purpose we need to first make a lightning tab which points to the lightning component we created and then we have to include that tab in the salesforc1 Mobile Navigation select list and the newly created tab to it.

11. Can we make a Lightning Component that shows up in both the mobile and the desktop user interfaces?

Lightning component is lightning experience ready by default and is also compatible in Salesforce1 App, it has a responsive layout therefore it adjust its resolution according the screen size and therefore can be used on desktop as well without writing any separate code.

12. Is Lightning component framework an MVC framework ?

No it is not a MVC framework it is a component based framework and event driven.

13. Which parts of Lightning Components are server-side and which are client-side ?

Lightning components have two types of controller, one which uses javascript and responds to the event occurring in the components at client side and the second controller which is an apex class. Method of apex controller are accessed by the JavaScript controller methods asynchronously.

14. Can we make one component inherit styles/CSS from a parent component, or must we always define it in the component ?

Child component inherits the CSS from its aren’t we do not need to specify it for each component

15. What is the use of the aura:method tag in Lightning ?

aura:method is used to communicate down the containment hierarchy i.e. parent to child

16. Can we Include One Lightning component to another ?

Yes we can include one Lightning component in another Lightning component

17. Is there any limit on how many component to have in one Application?

There is no limit on number of components defined within an application by salesforce

18. Is Lightning Components replacing Visualforce?

No Lightning component is not replacing Visualforce, Visualforce is still supported by Salesforce.

19. What is Aura? Why do we use the aura: namespace in the code?

Aura is a UI framework for developing dynamic web apps for mobile and desktop devices. Aura provides a scalable long-lived lifecycle to support building apps engineered for growth.

Aura supports partitioned multi-tier component development that bridges the client and server. It uses JavaScript on the client side and Java on the server side.

20. Do we need a namespace to develop Lightning Components?

You can have namespace in your org but it is not necessary to have a namespace to develop lightning component.

21. What are the tools included in lightning?

Lightning App Builder – It is a tool with User interface to use drag and drop functionality and create app fast by reusing the components, components can be standard or custom depending upon your requirement.
Lightning Component Framework- it provides a bundle that can be used to build reusable custom components, Standalone App and to customize Salesforce1 App
Lightning Connect – it is a powerful tool to facilitate the integration of force.com app with an external data source using OData specification
Lightning Process Builder – it is a visualization tool to build automation required for your business processes.
Lightning Schema Builder – it is a visualizing tool to view, create objects fields and relationship among them.

22. What is difference between Visualforce Components and Lightning Components?

Visualforce page is created keeping page as the center of the application and most of its calculation is performed at the server side. Lightning component on the other hand are created using the component based framework, most of the calculations are performed at the client side and makes the more dynamic and provide rich customer experience, also lightning component are build using mobile first approach.

23. Does Lightning work with Visualforce ?

Yes Lightning component works with Visualforce by implementing Lightning out as discussed earlier.

24. Are there any CSS (styles) provided by salesforce.com as part of the supported Lightning Components ?

Salesforce has provided lightning design system as the default css to be used with Lightning component.

25. Are Lightning Components intended only for mobile apps?

Although lightning framework creates component keeping mobile first approach, but its responsive design helps in providing the same experience over the desktop without writing separate lines of code

26. What are the advantages of lightning?

There are many advantages of using lightning like its out of the box component set which enables the fast paced creation of new apps, its event driven architecture which enables the easy decoupling between the components. Device awareness, cross browser compatibility and framework optimized for the performance.

27. Can we integrate Lightning components with another framework, such as Angular?

Yes we can integrate lightning with any 3rd party framework.

28. Can we include external JavaScript/CSS libraries in components?

It is possible to use custom CSS and JAvascriipt in the Lightning component

29. What happens with existing Visualforce Pages in Lightning Experience?

Most of the Visualforce page can be easily converted to lightning experience, but they are still supported by the salesforce and are not required to be converted

30. Where we can display lightning component?

Lightning component can be displayed at following places:
1. Lightning Experience
2. Salesforce1 App
3. Template-based Community
4. Standalone Lightning App
5. Visualforce Pages (Using Lightning out )

31. Do I always create an app bundle first when develop lightning component ?

No it is not necessary to create an Appp Bundle first to develop the lightning component

32. How can we deploy components to production org?

Lightning component can be deployed to the production via change sets, force.com IDE, Managed Package.

33. What is Lightning Experience?

It is the new user Interface developed by salesforce team, which is built on component based framework and event driven architecture, which provides a dynamic and responsive Experience to the user. This framework is built to provide optimum performance by using stateful Client side and stateless Server architecture

34. What is the use of implements in lightning component?

Implements is use to refer platform interfaces which enables a component to be used in different contexts or to grant access to extra context data, a component can implement more than one interfaces.

35. What is aura:registerevent in lightning component?

aura:registerevent is the notifier component and it declares that it may fire a particular event, it includes ‘name’ attribute which is relevant only to component event and is not used for application event. Other attribute is the ‘type’ which lets the component know which event would be fired.

Ex. <aura:registerEvent name=”Event” type=”c:EventName”/>

36. How can we subscribe to an event in lightning component?

To subscribe to an event in lightning component we need to include tag in the containment hierarchy. Subscription of these event depends on the event type i.e. component event or application event. For Component event we write below code.

In this ‘name’ attribute in should be exactly as name attribute in tag in the component which has fired the component. The ‘action’ attribute of sets the client-side controller action to handle the event. The ‘event’ attribute specifies the event being handled.
For Handling Application event we write below code

‘Event’ and ‘action’ attribute are same as the component event handling, it is just that we do not include ‘name’ attribute to handle the application event.

37. How can we communicate between two component?

In Lightning Component Framework, the communication between two component is accompalished supported in several ways.
1. Attributes or Methods to pass data down the component hierarchy
2. Lightning Events to pass data up and around in the component hierarchy

38. What is aura definition bundle?

It represents a Lightning definition bundle, it contains a Lightning definition and all its related resources. It could define a component, application, event, interface, or a tokens collection.

An AuraDefinitionBundle component is a collection of component definition files, each representing a different resource such as markup code, event documentations, applications and interfaces.

Lightning bundles must be under a top-level folder that’s named aura. Each bundle must have its own subfolder under the aura folder.

A bundle doesn’t have a suffix but definition files can have one of these suffixes
Suffix Component Type

Suffix

Component Type
.app Application
.cmp Component
.design Design
.evt Event
.intf Interface
.js Controller, Helper, or Renderer
.svg SVG image
.css Style
.auradoc Documentation
.tokens Tokens collection

39. What is aura:attribute?

They are same as member variable in apex classes, they are typed fields and are instance of a component. Attribute helps in making component more dynamic.

All attributes have a name and a type can be marked required by specifying ‘required=true’and can also have a default value. It has a naming rule as well:

1. Must begin with a letter or an underscore
2. Must contain only alphanumeric or underscore characters

40. What is lightning: or ui: in any lightning component?

Lightning has provided us with common User Interface components in the ui namespace which are used in the lightning component framework. They are ui:input and ui:output provide easy to implement common user interface.
Component with lightning namespace also provides us with the user interface but on top of that they include lightning design system CSS by default so we do not have to worry about the styling of these components.
41. How can we extend any component?

To make a component extendable we need to set value of ‘extensible’ attribute as ‘true’ of the aura:component tag.
When a component extends another component it inherits all of the helper methods and attributes

42. How to register, fire and handle a component and application event?

We register an event by by using the following code

<aura:registerEvent name=”sampleComponentEvent” type=”c:compEvent”/>

We fire event as shown below:

var compEvent = cmp.getEvent(“sampleComponentEvent”);

compEvent.fire();

Handle component event as below :

<aura:handler name=”sampleComponentEvent” event=”ns:eventName”

    action=”{!c.handleComponentEvent}” phase=”capture” />

Handle Application event as below:

<aura:handler event=”c:appEvent” action=”{!c.handleApplicationEvent}”/>

43. Let’s say that you have an app myApp.app that contains a component myCmp.cmp with a ui:button component. During initialization, the init() event is fired in what order?

ui:button, ui:myCmp, and myApp.app.

44. Why do we use @AuraEnabled annotation?

The AuraEnabled annotation provides support for Apex methods and properties to be used with the Lightning Component framework.
The AuraEnabled annotation is overloaded, and is used for two separate and distinct purposes.
1. Use @AuraEnabled on Apex class static methods to make them accessible as remote controller actions in your Lightning components.
2. Use @AuraEnabled on Apex instance methods and properties to make them serializable when an instance of the class is returned as data from a server-side action.

45. Why do we use $A.enqueueAction(action)?

It adds the server-side controller action to the queue of actions to be executed. Rather than sending a separate request for each individual action, the framework processes the event chain and batches the actions in the queue into one request. The actions are asynchronous and have callbacks.

46. Use of THIS CSS class?

This adds namespacing to CSS and helps prevent one component’s CSS from blowing away another component’s styling.

47. What are the different ways to conditionally display markup, and what is the preferred approach?

Using the <aura:if> tag
Use CSS to toggle visibility of markup by calling $A.util.toggleClass(cmp, ‘class’) in JavaScript code.

47. What is $Resource global value provider? Is it possible to obtain a reference to a static resource in Javascript code?

It lets you reference images, style sheets, and JavaScript code you’ve uploaded in static resources.

To obtain a reference to a static resource in JavaScript code, use $A.get(‘$Resource.resourceName’).

48. Let’s say you have several buttons that reuse the same onclick handler. How will you retrieve the name of the button that fired the event?

Use event.getSource() in the client-side controller to get the button component that was clicked. Call

getLocalId() to get the aura:id of the clicked button.

49. What are the names of interfaces that are added to a Lightning component to allow it to be used as custom tabs, and to be used in Lightning and Community builder?

‘force:appHostable’ Allows a component to be used as a custom tab in Lightning Experience or the Salesforce app
‘forceCommunity:availableForAllPageTypes’ To appear in Community Builder, a component must implement the forceCommunity:availableForAllPageTypes interface

50. What is the use of force:hasRecordId interface?

Add the force:hasRecordId interface to a Lightning component to enable the component to be assigned the ID of the current record.
The recordId attribute is set only when you place or invoke the component in a context of a record. For example, when you place the component on a record page, or invoke it as an action from a record page or object home. In all other cases, such as when you create this component programmatically inside another component, recordId isn’t set, and your component shouldn’t depend on it.

51. What is Lightning Design System (SLDS)?

The Salesforce Lightning Design System (SLDS) component library is actively developed to enable Salesforce developers to create a uniform look and feel across all Salesforce-related applications while adhering to CSS best practices and conventions.

52. What is the use of access=“global”?

The framework enables you to control access to your applications, attributes, components, events, interfaces, and methods via the access system attribute. The access system attribute indicates whether the resource can be used outside of its own namespace.
You can specify these values for the access system attribute.

Private: Available within the component, app, interface, event, or method and can’t be referenced outside the resource. This value can only be used for or .Marking an attribute as private makes it easier to refactor the attribute in the future as the attribute can only be used within the resource.
Accessing a private attribute returns undefined unless you reference it from the component in which it’s declared. You can’t access a private attribute from a sub-component that extends the component containing the private attribute.

Public: Available within your org only. This is the default access value.

Global: Available in all orgs.

53. What is Lightning Data Services?

They are similar to a standard controller in Apex coding, advantages of using lightning Data service are mentioned below
1. Use Lightning Data Service to load, create, edit, or delete a record in your component without requiring Apex code.
2. Lightning Data Service handles sharing rules and field-level security for you.
3. In addition to not needing Apex, Lightning Data Service improves performance and user interface consistency.

54. What are Local and Global ids with respect to lightning component?

Component IDs
A component has two types of IDs: a local ID and a global ID. You can retrieve a component using its local ID in your JavaScript code. A global ID can be useful to differentiate between multiple instances of a component or for debugging purposes.

Local IDs
A local ID is an ID that is only scoped to the component. A local ID is often unique but it’s not required to be unique.
Create a local ID by using the aura:id attribute. For example:
Find the button component by calling cmp.find(“button1”) in your client-side controller, where cmp is a reference to the component containing the button.

Global IDs
Every component has a unique globalId, which is the generated runtime-unique ID of the component instance. A global ID (1) is not guaranteed to be the same beyond the lifetime of a component, so it should never be relied on. A global ID can be useful to differentiate between multiple instances of a component or for debugging purposes.

55. What is a FlexiPage in lightning?

FlexiPage
Represents the metadata associated with a Lightning page. A Lightning page represents a customizable screen made up of regions containing Lightning components.
A Lightning page region can contain upto 25 components.

Lightning pages are referred as FlexiPages in API and referred as Lightning pages elsewhere in SFDC documentation

56. How to make quick lightning action?

Add the force:lightningQuickAction or force:lightningQuickActionWithoutHeader interface to a Lightning component to enable it to be used as a custom action in Lightning Experience or the Salesforce mobile app. You can use components that implement one of these interfaces as object-specific or global actions in both Lightning Experience and the Salesforce app.

57. What are value providers in Salesforce Lightning ?
Value providers helps use to access data in Lightning Application .They are two value providers as v(View) and c(controller)
v is component attribute set which helps to access component attribute values in markup
c is component controller helps us to link with event handlers and action for the component

58. List of Global value providers?

$globalID
$Browser
$Label
$Locale
$Resource

59. What are list of tools are avaliable in salesforce lightning ?

Lightning Connect
Lightning Component Framework
Lightning Schema Builder
Lightning Process Builder
Lightning App Builder

The answer to the questions have been referred from https://developer.salesforce.com and are reiterated in my language. Please go to the community to better understand the concept and enhance your knowledge, meanwhile use this post a help during your interview.
Keep learning.

Also, Have a look at the below resources:

  1. Best Salesforce Interview Questions book with Apex and Visualforce concept explained

Also, Have a look at the below learning resources:

  1. SOQL (Salesforce Object Query Language)

  2. Apex Trigger Best Practices and the Trigger Framework

  3. Salesforce Interview Question and Answers Part 2

  4. Salesforce Interview Questions on Test Class

The post Top 50 Salesforce Lightning Interview Questions 2018 appeared first on Salesforce Next Gen.

]]>
https://salesforcenextgen.com/salesforce-lightning-interview-questions-2018/feed/ 2